Hero doesn't attack - kithgard Brawl

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)

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”.

2 Likes

Thanks a lot for your reply!