// Lure the ogres into a trap.
// But, they are careful.
// These ogres will only follow the hero if the hero is injured.
// This function checks the hero's health and returns a Boolean value.
function shouldRun() {
if (hero.health < hero.maxHealth / 2) {
return true;
} else {
return false;
}
}
while (true) {
// Run to the X only if the hero shouldRun().
if shouldRun() {
hero.moveXY(76, 37);
// Otherwise, fight!
} else {
enemy = hero.findNearestEnemy();
hero.attack(enemy);
}
function shouldRun() {
if (hero.health < hero.maxHealth / 2) {
return true;
} else {
return false;
}
}
while (true) {
var enemy = hero.findNearestEnemy();
if (enemy != “Heizenburg”) {
hero.attack(enemy); // Move to the X only if shouldRun() returns true
}
hero.moveXY(75, 37);
}
Please learn to your code from the game from now on and use the </> button or it won’t format properly. When you click the </> button, the following will appear:
There are many people here willing and able to help. If you use the </> button correctly, your code should look like this:
while True:
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
else:
hero.say("My code is formatted properly")
If it doesn’t look like the code above, you’re doing it wrong and we can’t see the structure of the code to troubleshoot whether or not that is the issue. Use the </> button and help us help you. This works when sending a private message as well. Thank you.