# Forest Miners confusion

**URL:** <https://discourse.codecombat.com/t/forest-miners-confusion/9415>\
**Category:** Level Help\
**Created:** [October 21, 2016, 7:30pm UTC](https://discourse.codecombat.com/t/forest-miners-confusion/9415 "2016-10-21T19:30:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kizzykat](https://avatars.discourse-cdn.com/v4/letter/k/858c86/32.png) [@Kizzykat](https://discourse.codecombat.com/u/Kizzykat)\
**Post date:** [October 21, 2016, 7:30pm UTC](https://discourse.codecombat.com/t/forest-miners-confusion/9415/1 "2016-10-21T19:30:57Z")

</div>

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.

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

```

 ![](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/8/86597c27e823b51e0f327b895157df28d2c6e577.jpg)

So why am I failing?

---

<div class="post-metadata">

**Author:** ![Harry\_the\_Wanderer](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/harry_the_wanderer/32/5369_2.png) [@Harry\_the\_Wanderer](https://discourse.codecombat.com/u/Harry_the_Wanderer)\
**Post date:** [October 21, 2016, 10:38pm UTC](https://discourse.codecombat.com/t/forest-miners-confusion/9415/2 "2016-10-21T22:38:07Z")

</div>

are you wearing the same gear?

---

<div class="post-metadata">

**Author:** ![Kizzykat](https://avatars.discourse-cdn.com/v4/letter/k/858c86/32.png) [@Kizzykat](https://discourse.codecombat.com/u/Kizzykat)\
**Post date:** [October 22, 2016, 12:08am UTC](https://discourse.codecombat.com/t/forest-miners-confusion/9415/3 "2016-10-22T00:08:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![JEFF](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/jeff/32/11761_2.png) [@JEFF](https://discourse.codecombat.com/u/JEFF)\
**Post date:** [April 15, 2020, 11:17pm UTC](https://discourse.codecombat.com/t/forest-miners-confusion/9415/4 "2020-04-15T23:17:31Z")

</div>

I NEED HELP

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

```

---

<div class="post-metadata">

**Author:** ![brooksy125](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/brooksy125/32/9966_2.png) [@brooksy125](https://discourse.codecombat.com/u/brooksy125)\
**Post date:** [April 16, 2020, 12:20am UTC](https://discourse.codecombat.com/t/forest-miners-confusion/9415/5 "2020-04-16T00:20:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![JEFF](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/jeff/32/11761_2.png) [@JEFF](https://discourse.codecombat.com/u/JEFF)\
**Post date:** [April 20, 2020, 6:28pm UTC](https://discourse.codecombat.com/t/forest-miners-confusion/9415/6 "2020-04-20T18:28:30Z")

</div>

All done  
thx 😃 😃

---

<div class="post-metadata">

**Author:** ![Lincoln\_Whiteley](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/lincoln_whiteley/32/27510_2.png) [@Lincoln\_Whiteley](https://discourse.codecombat.com/u/Lincoln_Whiteley)\
**Post date:** [January 26, 2022, 12:54am UTC](https://discourse.codecombat.com/t/forest-miners-confusion/9415/7 "2022-01-26T00:54:25Z")

</div>

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