# "Long-Range Division" is impossible - hostage dies

So I’ve gotten to the level “Long-Range Division”, and there is a problem. One of the level’s goals is that the hostage must survive, but whatever I do, the ogres kill him. According to other threads, my code is correct, but when I approach the two ogres, they immediately kill the hostage before I can fight them. Any ideas on what to do?

Here is my code:

Code

# Use division to calculate the range.

enemy = hero.findNearestEnemy()
distanceToEnemy = hero.distanceTo(enemy)

# Say first Range: distanceToEnemy divided by 3

hero.say(distanceToEnemy/3)
hero.say(“Fire!”)

# Say second range: distanceToEnemy divided by 1.5

hero.say(distanceToEnemy/1.5)
hero.say(“Fire!”)

# Say these things for motivation. Really. Trust us.

hero.say(“Woo hoo!”)
hero.say(“Here we go!”)
hero.say(“Charge!!”)

# Now, use a while-true loop to attack the enemies.

while True:
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)

2 Likes

Try equipping your hero with faster boots and the Speed Ring, if necessary. If you are a subscriber, try using a faster hero like Pender.

2 Likes

Hi there,
We made a few changes to the way CodeCombat runs, and it has made some older levels behave in slightly strange ways.

For example, on this level, it made the ogres attack the hostage before any warriors got close enough to fight.

Our good friend Bryukh has already fixed this, but there may be more out there. Please keep letting us know if you see something strange.

Please hide your code, @Enderhippo – we try not to have successful code on the forums.

Maka

3 Likes

Thank you so much! (the code is hidden now as well)

2 Likes

Good day, looks like a bug is still exists.
After killing the first enemy the hero stop and cant complete the lvl.

Thank you.

Hi @Sayaf Welcome to the Discourse
For the bug I don’t think @maka is active anymore.

Maybe there is someone else from the administration.

Hi Sayaf,

Welcome to the forum!

It might be a bug, but it might also be an issue in your code. Could you post your code (formatting instructions at [Essentials] How To Post/Format Your Code Correctly), and we can try to run it… We can then give you help if it’s a code issue, or give more information to CoCo if it’s a bug.

Jenny

var enemy = hero.findNearestEnemy();
var distanceToEnemy = hero.distanceTo(enemy);
// Say first Range: distanceToEnemy divided by 3
distanceToEnemy / 3;
hero.say(distanceToEnemy / 3);
// Say second range: distanceToEnemy divided by 1.5
distanceToEnemy / 1.5;
hero.say(distanceToEnemy / 1.5);
// Say these things for motivation. Really. Trust us.
hero.say("Woo hoo!");
hero.say("Here we go!");
hero.say("Charge!!");
// Now, use a while-true loop to attack the enemies.
while (true) {
if (enemy) {
hero.attack(enemy);
}
}

Also Tried to put name of the Enemy as an argument, but still cant attack second ogre.

Thank you.

Put

var enemy = hero.findNearestEnemy();

inside the while loop. That way the second time the loop runs the other ogre is set as the enemy.

Jenny

1 Like

Thank you very much!