Range Finder Help

I am stuck on range finder

``````# Ogres are scouting the forest!
# Use the distanceTo method to find where the enemies are.
# Say the distance for each enemy to tell the artillery where to fire!

enemy1 = "Gort"
distance1 = hero.distanceTo(enemy1)
hero.say(distance1)

enemy2 = "Smasher"
distance2 = hero.distanceTo(enemy2)
# Say the distance2 variable!
hero.say("distance2")
# Don't shoot at your friends!
friend3 = "Charles"

# The last ogre.
enemy4 = "Gorgnub"
# Find and say the distance to enemy4:
hero.say("distance4")

``````

In the first one, you are defining a variable (the distance to Gort) and then saying it, so the result would be your hero saying a number, like 3. For the second one, your hero would say distance2.

Thatâ€™s what I did but itâ€™s not working.

You are saying â€śdistance2â€ť when you are supposed to be saying the distance to enemy2, which is in the variable distance2.

1 Like
``````enemy1 = "Gort"
distance1 = hero.distanceTo(enemy1)
hero.say(distance1)
enemy2 = "Smasher"
# Say the distance2 variable!
distance2 = hero.distanceTo(enemy2)
hero.say("distance2")
# Don't shoot at your friends!
friend3 = "Charles"

# The last ogre.
enemy4 = "Gorgnub"
# Find and say the distance to enemy4:
distance4 = hero.distanceTo(enemy4)
hero.say("distance4")
``````

You mean like this

1 Like

Look closely at that. What happens if you say distance1 is you say whatever is in the variable distance1, in this case, your distance to Gort. If you say â€śdistance1â€ť, what your hero says is â€śdistance1â€ť

1 Like
``````enemy1 = "Gort"
distance1 = hero.distanceTo(enemy1)
hero.say("Gort")

enemy2 = "Smasher"
# Say the distance2 variable!
distance2 = hero.distanceTo(enemy2)
hero.say("Smasher")

# Don't shoot at your friends!
friend3 = "Charles"
# The last ogre.

enemy4 = "Gorgnub"
# Find and say the distance to enemy4:
distance4 = hero.distanceTo(enemy4)
hero.say("Gorgnub")
``````
1 Like

Read the comment. Youâ€™ve already found the distance and put it in the distance4 variable. Now all you have to do is say it. Using hero.say(), say the variable distance4 like

And repeat for the other ones.

1 Like

Okay thanks it worked this time.

2 Likes

I does not work for me And I am using Python.

1 Like

You should not be taking other peopleâ€™s code and use it for your own.
Lydia

1 Like

@Gabriel_Knight , you should be defining the enemy distance like you did. All you have to change is your `hero.say` Lines. Replace those with `Hero.say (distance1)`, `hero.say(distance2)` and `hero.say(distance4)`. If you put quotation marks the hero only says â€ždistance1â€ś, â€ždistance2â€ś or â€ždistance4â€ś and not the actual distance to the enemy.

Mumbo_6

2 Likes

@Lydia_Song I think he just wanted to help out aswell.

2 Likes

In order for me to solve it I had to do to `hero.say(distance1)` and so on and so forth.

heres my code
enemy1 = â€śGortâ€ť
distance1 = hero.distanceTo(enemy1)
hero.say(â€śGortâ€ť)

enemy2 = â€śSmasherâ€ť
distance2 = hero.distanceTo(enemy2)

Say the distance2 variable!

hero.say(â€śSmasherâ€ť)

friend3 = â€śCharlesâ€ť

The last ogre.

enemy4 = â€śGorgnubâ€ť

Find and say the distance to enemy4:

distance4 = hero.distanceTo(enemy4)
hero.say(â€śGorgnubâ€ť)

Hallo! Can you please format your code by using the </> button?

``````enemy1 = "Gort"
distance1 = hero.distanceTo(enemy1)
hero.say(distance1)

enemy2 = "Smasher"
distance2 = hero.distanceTo(enemy2)
# Say the distance2 variable!
hero.say(distance2)
# Don't shoot at your friends!
friend3 = "Charles"

# The last ogre.
enemy4 = "Gorgnub"
# Find and say the distance to enemy4:
distance = hero.distanceTo(enemy4)
hero.say("distance4")
``````

idk what i did wrong

Youâ€™re in the forest right?