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
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!
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
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.