So my husband has the exact same code as me, and passed the level, but for some reason its not letting me do so. The enemy seems like he spawns a second or so too late.
# Check if the mines are safe for the workers.
def checkEnemyOrSafe(target):
# If target (the parameter) exists:
if target:
# Then attack target.
hero.attack(target)
# Otherwise use say() to call the peasants.
else:
hero.say("Clear")
pass
while True:
# Move to, and check the top right X mark.
hero.moveXY(64, 54)
enemy = hero.findNearestEnemy()
checkEnemyOrSafe(enemy)
# Move to the bottom left X mark.
hero.moveXY(16, 14)
# Save the result of findNearestEnemy() in a variable.
enemy = hero.findNearestEnemy()
# Call checkEnemyOrSafe(), and pass the
# result of findNearestEnemy as the argument.
checkEnemyOrSafe(enemy)
# This function should check the if there is 'target' or it's safe.
def checkEnemyOrSafe(target):
# Write this function.
# If 'target' exist, then attack it.
# Otherwise say something to call peasants.
if target:
hero.attack(target)
else:
hero.say('yahoo')
pass
# Move and check the marks: the top right first, then the bottom left one.
while True:
# Move and check the top right point.
hero.moveXY(64, 54);
enemy = hero.findNearestEnemy()
checkEnemyOrSafe(enemy)
# Move and check the bottom left point.
hero.moveXY(16, 14);
enemy2 = hero.findNearestEnemy()
checkEnemyOrSafe(enemy)
// If `target` (the parameter) exists:
if (target) {
// Then attack target.
hero.attack(target);
// Otherwise:
} else {
// Use say() to call the peasants.
hero.say("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
checkEnemyOrSafe();
// result of findNearestEnemy as the argument.
checkEnemyOrSafe(enemy2);
}
}```
I need help! Why isn't this working?