# Hero doesn't attack - kithgard Brawl

**URL:** <https://discourse.codecombat.com/t/hero-doesnt-attack-kithgard-brawl/5029>\
**Category:** Uncategorized\
**Created:** [September 24, 2015, 9:46pm UTC](https://discourse.codecombat.com/t/hero-doesnt-attack-kithgard-brawl/5029 "2015-09-24T21:46:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_Estudillo](https://avatars.discourse-cdn.com/v4/letter/a/94ad74/32.png) [@Alex\_Estudillo](https://discourse.codecombat.com/u/Alex_Estudillo)\
**Post date:** [September 24, 2015, 9:46pm UTC](https://discourse.codecombat.com/t/hero-doesnt-attack-kithgard-brawl/5029/1 "2015-09-24T21:46:17Z")

</div>

Hello all. I am playing kithgard Brawl. My code seems to work fine at the beginning, but after 15 seconds, my hero stop attacking enemies for a while. Importantly, this happens before the medicine appears. Any ideas?

```
 loop:
        enemy = self.findNearestEnemy()
        item = self.findNearestItem()
        if item:
            position = item.pos
            x = position.x
            y = position.y
            if self.health < 200:
                self.moveXY(x, y)    
        elif enemy:
            distance = self.distanceTo(enemy)
            if distance < 5 and self.isReady("cleave"):  
                self.cleave(enemy)
            elif enemy.type is "ogre" and self.isReady("bash"):
                self.bash(enemy)
            else:
                self.attack(enemy)
```

---

<div class="post-metadata">

**Author:** ![Zhio](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/zhio/32/3007_2.png) [@Zhio](https://discourse.codecombat.com/u/Zhio)\
**Post date:** [September 25, 2015, 4:50am UTC](https://discourse.codecombat.com/t/hero-doesnt-attack-kithgard-brawl/5029/2 "2015-09-25T04:50:18Z")

</div>

What’s happening is your code runs correctly from the start because there are no items on the field.  
It checks items and finds none, so your hero goes about killing.  
Once an item appears, your loop constantly goes into your “if item:” loop and checks for your health being below 200  
Until it gets below 200, your hero just stands there.  
To fix this, try moving the health check up to the if statement.  
You can check more than one statement at a time using “and”.

---

<div class="post-metadata">

**Author:** ![Alex\_Estudillo](https://avatars.discourse-cdn.com/v4/letter/a/94ad74/32.png) [@Alex\_Estudillo](https://discourse.codecombat.com/u/Alex_Estudillo)\
**Post date:** [September 25, 2015, 12:16pm UTC](https://discourse.codecombat.com/t/hero-doesnt-attack-kithgard-brawl/5029/3 "2015-09-25T12:16:26Z")

</div>

Thanks a lot for your reply!
