# Woodland Cleaver Target Issue

**URL:** <https://discourse.codecombat.com/t/woodland-cleaver-target-issue/1701>\
**Category:** Bugs\
**Created:** [December 10, 2014, 7:17pm UTC](https://discourse.codecombat.com/t/woodland-cleaver-target-issue/1701 "2014-12-10T19:17:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![xmdz](https://avatars.discourse-cdn.com/v4/letter/x/35a633/32.png) [@xmdz](https://discourse.codecombat.com/u/xmdz)\
**Post date:** [December 10, 2014, 7:17pm UTC](https://discourse.codecombat.com/t/woodland-cleaver-target-issue/1701/1 "2014-12-10T19:17:36Z")

</div>

I’m attempting to complete “Woodland Cleaver”, but it continues to call my target “enemy” null, despite the fact that the enemy is identified at the beginning of the loop and the code runs properly for half the level before locking down and failing because of this issue.

The code I have is as follows, including the sample code and text.

```python
# Use your new "cleave" skill as often as you can.

self.moveXY(23, 23)
loop:
    enemy = self.findNearestEnemy()
    if self.isReady("cleave"):
        # Cleave the enemy!
        self.cleave(enemy)

    else:
        # Else (if cleave isn't ready), do your normal attack.
        self.attack(enemy)

```

I’ve looked around and based on the posts in the main topic for Woodland Cleaver, and the sample text of the level, this seems like it should be the proper solution.

EDIT: I’ve managed to bypass this by creating a larger “if” and putting it around the if/else statements already in place so that it only performs them if an enemy is present.

---

<div class="post-metadata">

**Author:** ![geof\_ericson](https://avatars.discourse-cdn.com/v4/letter/g/f6c823/32.png) [@geof\_ericson](https://discourse.codecombat.com/u/geof_ericson)\
**Post date:** [December 10, 2014, 7:53pm UTC](https://discourse.codecombat.com/t/woodland-cleaver-target-issue/1701/2 "2014-12-10T19:53:27Z")

</div>

I, too, was having this same issue. My solution was to remove the self.moveXY at the beginning of the code. Hope this helps someone else.

---

<div class="post-metadata">

**Author:** ![nick](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/nick/32/784_2.png) [@nick](https://discourse.codecombat.com/u/nick)\
**Post date:** [December 10, 2014, 9:14pm UTC](https://discourse.codecombat.com/t/woodland-cleaver-target-issue/1701/3 "2014-12-10T21:14:17Z")

</div>

Thanks for the heads up on this one, guys. I’ve tuned the visibility and spawn rates a bit such that you’re less likely to kill all the enemies early and then error out on a null target. In general, surrounding things like this in an `if` to make sure there is an enemy there is a great tactic! We just wanted this one to be easier, so hopefully now it is.

---

<div class="post-metadata">

**Author:** ![hi\_there\_samyak\_verm](https://avatars.discourse-cdn.com/v4/letter/h/b487fb/32.png) [@hi\_there\_samyak\_verm](https://discourse.codecombat.com/u/hi_there_samyak_verm)\
**Post date:** [January 9, 2015, 12:34am UTC](https://discourse.codecombat.com/t/woodland-cleaver-target-issue/1701/4 "2015-01-09T00:34:21Z")

</div>

Another thing is happening because it keeps saying there is a problem with the the beginning code, it keeps saying please put in 4 spaces and also puts in error invalid token. I have checked everything but nothing is working. Please help.

---

<div class="post-metadata">

**Author:** ![nick](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/nick/32/784_2.png) [@nick](https://discourse.codecombat.com/u/nick)\
**Post date:** [January 9, 2015, 2:06am UTC](https://discourse.codecombat.com/t/woodland-cleaver-target-issue/1701/5 "2015-01-09T02:06:08Z")

</div>

The sample code has the problem because there is an empty `if` statement in it. You need to fill in the if statement body on like 8 and the else statement body on line 11, and then it will be complete and stop giving a warning.

---

<div class="post-metadata">

**Author:** ![Michael\_Moore](https://avatars.discourse-cdn.com/v4/letter/m/ecd19e/32.png) [@Michael\_Moore](https://discourse.codecombat.com/u/Michael_Moore)\
**Post date:** [April 30, 2015, 2:50am UTC](https://discourse.codecombat.com/t/woodland-cleaver-target-issue/1701/6 "2015-04-30T02:50:35Z")

</div>

Ran into this issue today, below is my code, received the null target error and was able to successfully complete by running the code a second time:

```
 # Use your new "cleave" skill as often as you can.

 self.moveXY(23, 23)
 loop:
     enemy = self.findNearestEnemy()
     if self.isReady("cleave"):
         # Cleave the enemy!
         self.cleave(enemy)
    
     else:
         # Else (if cleave isn't ready), do your normal attack.
         self.attack(enemy)
```

---

<div class="post-metadata">

**Author:** ![nick](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/nick/32/784_2.png) [@nick](https://discourse.codecombat.com/u/nick)\
**Post date:** [April 30, 2015, 7:08pm UTC](https://discourse.codecombat.com/t/woodland-cleaver-target-issue/1701/7 "2015-04-30T19:08:52Z")

</div>

Hey Michael, what hero/weapon/boots were you using?
