Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

[SOLVED] Blind distance help!

can someone help me with this level i have this;

# 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: 
    distance = hero.distanceTo(enemy)>0
    # Say the value of enemyDistance variable.
    hero.say("distance")

but it doesn’t work

Think about what this line is trying to do. You need an if statement, and then use this to see if enemyDistance is greater than 0.

1 Like

okay thanks i’ll try that and let you know if it worked
:slight_smile:

1 Like

Here check if enemyDistance>0 and if it is true, then say enemyDistance.
And delete this

Andrei

how do i put that i did the if true: thing but it didnt work it says true is not defined

Can you show me your code?

Andrei

yes it says line 19 is wrong. 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: 
    enemy = hero.findNearestEnemy()
    enemyDistance>0
    if true:
        hero.say("enemyDistance")

1 Like

Put instead of that true this

Andrei

they still kill me when i do it

# 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: 
    enemy = hero.findNearestEnemy
    if enemyDistance>0:
        hero.say("enemyDistance")

I just put it above your reply

1 Like

Delete this signs " " from here.

Andrei

1 Like

thank you its working now i completed the level. :wink:

1 Like

No problem! And congratulations for completing the level! :partying_face:

Andrei

thanks, could’t have done it without you! :partying_face:

1 Like