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.

i need some help please

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”)

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”)

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?