Forest Miners confusion

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)

So why am I failing?

are you wearing the same gear?

1 Like

oh, I wasn’t using a fast enough sword…thanks. my bad.

I NEED HELP

# 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)

Take a look at your variable on the second checkEnemyOrSafe(?). What is the variable name you just created above it?

All done
thx :smiley: :smiley:

    // 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?