[SOLVED] Blind Distance

Hi, I have been on this level for quite some time now approx. 2.5 hours and I can’t figure out what is wrong with my code can someone help?
Here is my code:

# 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 hero.distanceTo > 0 : 
        # Say the value of enemyDistance variable.
1 Like

Remove the quotes in hero.say("nearestEnemyDistance()"). Quotes will make your hero say exactly what’s inside the quotes, but since you want to say the return value instead of just nearestEnemyDistance(), you’d have to change that to hero.say(nearestEnemyDistance())

1 Like

so it is line 19?

1 Like

The code gets stuck on the return command why is this?

1 Like

Change the if statement to:

if enemyDistance > 0:

Then inside of the if statement, say enemyDistance.


Thank you this helped a lot.


This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.