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

Help: Blind Distance[SOLVED]

i have been working on this level for days and I cant get past It i would like some clarification

my code doesn’t work and i would like help with how to make it better

def nearestEnemyDistance():
    enemy = hero.findNearestEnemy()
    result = 10 # you set the default distance to enemy to 10
    if enemy:  # and if there is no enemy
        result = hero.distanceTo(enemy)
    return result # the distance to enemy will be 10
                  # if there is no enemy
while True:
    enemyDistance = nearestEnemyDistance()
    if enemyDistance > 0: # this will be always true
                          # 10 or the real distance
        hero.say(enemyDistance)


result = 10 # or some other value

change that to zero

delete this

delete this
and welcome to the forum.

Hello and welcome to codecombat discourse @logan_jordan! This is a cozy forum where you can share ideas, share fan art, get assistance for code, etc! Before you proceed, we hope that you review this topic, which shows all essentials of this board! Thanks!

ok so what should i change the zero to?

for the rusult change the ten to a zero.

ok i did that and it still no work the wizard tires out

Post your code please.

def nearestEnemyDistance():
    enemy = hero.findNearestEnemy()
    result = 0 # you set the default distance to enemy to 10
    if enemy:  # and if there is no enemy
        result = hero.distanceTo(enemy)
    return result # the distance to enemy will be 10
                  # if there is no enemy
while True:
    enemyDistance = nearestEnemyDistance()
    if enemyDistance > 0: # this will be always true
                          # 10 or the real distance
        hero.say(enemyDistance)


result = 10 # or some other value

Delete that line.

oh wait it works now nevermind thankyou for the help

delete this.
20202022

remember to click the tickbox that says solved next to the post that helped most

Yes as @cheddarcheese mentioned please give the solution to whoever gave u the best answer @logan_jordan it helps because the system will automatically close the topic so that our mods don’t have to.

Thanks!
:wolf::wolf::wolf: