Python Blind Distance


#1

I’m trying to complete blind distance but i always run out of time because the wizard gets too tired too fast because he needlessly attacks when he doesn’t need too so i fail i have tried using stuff that isn’t involved in the level but no matter what it fails over and over its frustrating.


#2

Can you please post your code? :slight_smile:


#3

Here you go.

# Tell the wizard the distance to the coming ogres.

# This function finds the nearest enemy and returns the distance to it.
# If there is no enemy, the function returns 0.
def nearestEnemyDistance():
    enemy = hero.findNearestEnemy()
    result = 0
    if enemy:
        result = hero.distanceTo(enemy)
    return result

while True:
    # Call nearestEnemyDistance() and
    # save the result in the variable enemyDistance.
    enemyDistance = nearestEnemyDistance()
    # If the enemyDistance is greater than 0: 
    if enemyDistance<10 :
        # Say the value of enemyDistance variable.
        hero.say("10")


#4

Why would you command your hero to say("10")? Surely you defined the variable enemyDistance for a reason. Maybe for you need to say enemyDistance (hint :wink:)


#5

And of course now it works -_-


#6

What did you change to make it work?


#7

thx very much i solved it
been a great help
hope i enquire for more problems


#8

I want to know as well.
I am stuck on this level:yum:


#9

The 10 does not work for me why?


#10

If you want help with your code, please could you post it on the discourse (formatted as it states in the FAQ) and say what you’re having trouble with. Thanks :wink: (also I don’t think @innerdesert4346 is active any more)