[SOLVED] Range Finder HELP!

I’ve been trying to “conquer” the Range Finder level in backwoods forest. Here’s my code:

enemy1 = “Gort”
distance1 = hero.distanceTo(enemy1)
hero.say(distance1)

enemy2 = “Smasher”
distance2 = hero.distanceTo(enemy2)

Say the distance2 variable!

hero.say(distance2)
enemy3 = “Charles”
enemies = hero.findEnemies()
hero.attack(enemy3)
continue
enemy4 = “Gorgnub”
enemies = hero.findEnemies()
hero.attack(enemy4)

But the thing is I can’t reach and/or attack the ogre near the tent. Does anyone have any suggestions or help me reach the ogre?

5 Likes

Make sure you do not attack Charles. Delete the code for “enemy3”.

Also, do not use hero.attack. The mortar will fire for you. Instead of hero.attack(enemy4), find the distance to enemy4 using distanceTo and then say distance4

3 Likes

Also please format your code according to the FAQ. It helps us better understand you code and also helps us figure out what is wrong. Go to: https://discourse.codecombat.com/faq.

To format correctly, you would put triple (`)'s, around your code so that:

enemy = self.findNearestEnemy
if enemy:
self.attack(enemy)

becomes this:

enemy = self.findNearestEnemy
if enemy:
self.attack(enemy)

Cheers! :beers:

Please :heart: this post if you find it useful

6 Likes

Thanks, @Luke10. I never knew we were supposed to do that in the Discourse. And thanks, @_TD_RodYT. I completed that code thanks to you. :slight_smile:

3 Likes

(solution removed)

(20 characters minimum)

1 Like

Please don’t post solutions. The purpose of this board is to help people learn so that they can figure out levels on their own. Simply providing solutions does not help and is counterproductive to this goal. The two main rules here on this board are no swearing and no posting solutions. Thanks and welcome to the board.

1 Like

Guy’s i finally solved it here ill give u the code that i used.

Mod edit: Please don’t post solutions. The purpose of this board is to help people learn so that they can figure out levels on their own. Simply providing solutions does not help and is counterproductive to this goal. The two main rules here on this board are no swearing (be nice) and no posting solutions. Thanks and welcome to the board.

1 Like

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:

distance4 = hero.findNearestEnemy(enemy4)
distance = hero.distanceTo(enemy4)
hero.say(distance4)
Please help me

1 Like

Never mind about that

1 Like

did you get it?

because i need the correct code.

Hi @Forknife3. Welcome to the CodeCombat Discourse.
I’m very happy to help you with your code, but this forum isn’t for giving solutions. Because you learn a lot more from trying, with help if you’re stuck, than using someone else’s solution.
Thanks,
-Danny

Something I always missed was to understand the difference between hero.say (“enemy”) and hero.say (enemy)

ok um i attack before it is time to and when they all come at you at once it wont cleave. so I go back to breaking the chest and they kill me.

enemy1 = “Gort”
enemy2 = “Smasher”
enemy3 = “Charles”
enemy4 = “Gorgnub”

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

Артиллерия должна уничтожить Gort-а!

Найти расстояние к двум другим ограм.

distance2 = hero.distanceTo(enemy2)
hero.say(distance2)

Дайте команду стрелять, указав расстояние.

distance4 = hero.distanceTo(enemy4)
hero.say(distance4)

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!

this dose not work

@Jose_Lopez1 could you please make your own topic with your code. Please do not revive dead topics
thank you

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!

Falcons, necroposting is allowed if it’s related to the topic and @Jose_Lopez1 please post your code

Same is going on with me. Good Code by the way Emblu056

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!

Hey there,
Necroposting is allowed as long as the user posts a relevant post, in this case, he’s requesting help.