# Patrol Buster coding problem

**URL:** <https://discourse.codecombat.com/t/patrol-buster-coding-problem/3017>\
**Category:** Uncategorized\
**Created:** [March 9, 2015, 7:34pm UTC](https://discourse.codecombat.com/t/patrol-buster-coding-problem/3017 "2015-03-09T19:34:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Code\_Designer](https://avatars.discourse-cdn.com/v4/letter/c/ecc23a/32.png) [@Code\_Designer](https://discourse.codecombat.com/u/Code_Designer)\
**Post date:** [March 9, 2015, 7:34pm UTC](https://discourse.codecombat.com/t/patrol-buster-coding-problem/3017/1 "2015-03-09T19:34:02Z")

</div>

I am typing this into the box above Run:

# Remember that enemies may not yet exist.

loop:  
enemy = self.findNearestEnemy()  
# If there is an enemy, attack it!  
self.attack(self.findNearestEnemy())

It isn’t working, and I was wondering what was wrong. It keeps giving me

Fix Your Code:  
Line five: Target is null, is there always a target to attack?

Is there anything I can do? I’m running it in Python

---

<div class="post-metadata">

**Author:** ![Vettax](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/vettax/32/1514_2.png) [@Vettax](https://discourse.codecombat.com/u/Vettax)\
**Post date:** [March 9, 2015, 8:51pm UTC](https://discourse.codecombat.com/t/patrol-buster-coding-problem/3017/2 "2015-03-09T20:51:18Z")

</div>

Sorry, I don’t know the syntax in Python.  
But you need to test if enemy exist before attacking them.  
Something like:

```python
 enemy = self.findNearestEnemy()
# If there is an enemy, attack it!
if (enemy)
    self.attack(enemy)

```

in fact, you just do exactly what was requested in the comment…  
if (enemy) is equivalent to if(enemy!=null)

---

<div class="post-metadata">

**Author:** ![Code\_Designer](https://avatars.discourse-cdn.com/v4/letter/c/ecc23a/32.png) [@Code\_Designer](https://discourse.codecombat.com/u/Code_Designer)\
**Post date:** [March 9, 2015, 9:25pm UTC](https://discourse.codecombat.com/t/patrol-buster-coding-problem/3017/3 "2015-03-09T21:25:23Z")

</div>

I got it! Thank you!

---

<div class="post-metadata">

**Author:** ![MunchingBrotatoToday](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/munchingbrotatotoday/32/2266_2.png) [@MunchingBrotatoToday](https://discourse.codecombat.com/u/MunchingBrotatoToday)\
**Post date:** [April 4, 2015, 12:05pm UTC](https://discourse.codecombat.com/t/patrol-buster-coding-problem/3017/4 "2015-04-04T12:05:32Z")

</div>

Also thanks you help me a LOT!!!

---

<div class="post-metadata">

**Author:** ![Bones3435](https://avatars.discourse-cdn.com/v4/letter/b/3da27b/32.png) [@Bones3435](https://discourse.codecombat.com/u/Bones3435)\
**Post date:** [October 15, 2016, 7:23pm UTC](https://discourse.codecombat.com/t/patrol-buster-coding-problem/3017/5 "2016-10-15T19:23:02Z")

</div>

I need help with that level too but im using JavaScript, I’ve tried a lot of things but it doesn’t work! can some1 help me please??
