My hero keeps on attacking a enemy on the side:
My code:
// Check if the mines are safe for the workers.
function checkEnemyOrSafe(target) {
// If `target` (the parameter) exists:
if (target) {
hero.attack(target);
} else {
hero.say("All Clear!");
} // Then attack target.
// Otherwise:
// Use say() to call the peasants.
}
while (true) {
// Move to, and check the top right X mark.
hero.moveXY(64, 54);
var enemy1 = hero.findNearestEnemy();
checkEnemyOrSafe(enemy1);
// Move to the bottom left X mark.
hero.moveXY(16, 14);
// Save the result of findNearestEnemy() in a variable.
var enemy2 = hero.findNearestEnemy();
// Call checkEnemyOrSafe, and pass the
// result of findNearestEnemy as the argument.
checkEnemyOrSafe(enemy2);
}