Can I have help on blind distance

this 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:
hero.say(“10”)
# Say the value of enemyDistance variable.

Hello and welcome to codecombat discourse! 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!

It is important that we understand how your code is indented in Python to capture any mistakes related to that. Please read through the linked topic to learn how to do that.

I believe the issue is following the one line checking the distance. You are missing this part of code to make sure the distance is greater than 0.
# If the enemyDistance is greater than 0:

Also, make sure you say the variable, and not 10 like you currently have coded.

2 Likes

@brooksy125! Haven’t seen you on for a long time!

1 Like

Welcome back, we haven’t seen you in a while.

def nearestEnemyDistance():
enemy = hero.findNearestEnemy()
result = 10
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:
def nearestEnemyDistance():
enemy = hero.findNearestEnemy()
result = 10
if enemy:
result = hero.distanceTo(enemy)
return result

Don’t share any solutions here. The person wouldn’t learn nothing if you gave them working code.

You have to check if enemyDistance is greater than 0. If it is, say enemyDistance.

if enemyDistance > 0:
    hero.say(enemyDistance)

That’s nothing related to the topic, please refrain from posting stuff that is not related to the topic
Lydia

@21-Nikkil_Amarnath please read the rules carefully.
Welcome to CodeCombat Discourse Forums!