# Why does ''target is null'' display to me?

**URL:** <https://discourse.codecombat.com/t/why-does-target-is-null-display-to-me/3176>\
**Category:** Uncategorized\
**Created:** [March 20, 2015, 4:17pm UTC](https://discourse.codecombat.com/t/why-does-target-is-null-display-to-me/3176 "2015-03-20T16:17:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![AdsmeGames](https://avatars.discourse-cdn.com/v4/letter/a/b782af/32.png) [@AdsmeGames](https://discourse.codecombat.com/u/AdsmeGames)\
**Post date:** [March 20, 2015, 4:17pm UTC](https://discourse.codecombat.com/t/why-does-target-is-null-display-to-me/3176/1 "2015-03-20T16:17:08Z")

</div>

Hi,  
I’m on level Backwoods Brawl, and every time, when I attack, I get a message saying ‘‘target is null’’. I’m using this:

```python
enemy = self.findNearestEnemy()

loop:
    if self.isReady("power-up"):
        self.powerUp()
    else:    
        self.attack(enemy)          
        self.attack(enemy)

```

Can somebody help me?

---

<div class="post-metadata">

**Author:** ![Vlevo](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/vlevo/32/2074_2.png) [@Vlevo](https://discourse.codecombat.com/u/Vlevo)\
**Post date:** [March 20, 2015, 4:23pm UTC](https://discourse.codecombat.com/t/why-does-target-is-null-display-to-me/3176/2 "2015-03-20T16:23:28Z")

</div>

you are setting enemy OUTside the loop…(so it never changes)

---

<div class="post-metadata">

**Author:** ![bmmtstb](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/bmmtstb/32/12265_2.png) [@bmmtstb](https://discourse.codecombat.com/u/bmmtstb)\
**Post date:** [March 20, 2015, 5:43pm UTC](https://discourse.codecombat.com/t/why-does-target-is-null-display-to-me/3176/3 "2015-03-20T17:43:25Z")

</div>

please edit your code like this

```python
code
some more code

```

if you are looking for several enemies u have to find the enemy iside the loop.  
there is not everytime an enemy, use if/else to define what u do.

there are several posts in this forum about the same problem… if you would have searched u would have found a reason…  
[Try this…](http://discourse.codecombat.com/t/patrol-buster-help/2381/4?u=bmmtstb)

---

<div class="post-metadata">

**Author:** ![J\_F\_B\_M](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/j_f_b_m/32/2756_2.png) [@J\_F\_B\_M](https://discourse.codecombat.com/u/J_F_B_M)\
**Post date:** [March 20, 2015, 11:28pm UTC](https://discourse.codecombat.com/t/why-does-target-is-null-display-to-me/3176/4 "2015-03-20T23:28:06Z")

</div>

@bmmtstb

```python
like this

```

is not very helpful. I contacted AdsmeGames how to do it properly. The easiest way to show this to someone in the future is to simply point them to the FAQ.

---

<div class="post-metadata">

**Author:** ![Feinty](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/feinty/32/1869_2.png) [@Feinty](https://discourse.codecombat.com/u/Feinty)\
**Post date:** [March 22, 2015, 11:48pm UTC](https://discourse.codecombat.com/t/why-does-target-is-null-display-to-me/3176/5 "2015-03-22T23:48:34Z")

</div>

Another quick problem is that you are not checking if an enemy exists before you attack it
