# I need help with Village Warder

**URL:** https://discourse.codecombat.com/t/i-need-help-with-village-warder/17375
**Category:** Level Help
**Created:** [February 5, 2019, 12:24am UTC](https://discourse.codecombat.com/t/i-need-help-with-village-warder/17375 "2019-02-05T00:24:58Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![PinkiePie](https://avatars.discourse-cdn.com/v4/letter/p/439d5e/32.png) [@PinkiePie](https://discourse.codecombat.com/u/PinkiePie)
#### Post date: [February 5, 2019, 12:24am UTC](https://discourse.codecombat.com/t/i-need-help-with-village-warder/17375/1 "2019-02-05T00:24:58Z")

</div>

def findAndAttackEnemy():  
enemy = hero.findNearestEnemy()  
enemy = hero.findNearestEnemy()

hero.attack(enemy)

def findAndCleaveEnemy():  
# Define a function to cleave enemies (but only when the ability is ready).  
if enemy:  
hero.attack(enemy)  
enemy = hero.findNearestEnemy()  
enemy = hero.findNearestEnemy()

hero.cleave(enemy)  
pass

while True:  
# Move to the patrol point, cleave, and attack.  
hero.moveXY(35, 34)  
findAndCleaveEnemy()  
findAndAttackEnemy()

hero.moveXY(60, 31)  
findAndCleaveEnemy()  
findAndAttackEnemy()

---

<div class="post-metadata">

### Author: ![123hi123](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/123hi123/32/9541_2.png) [@123hi123](https://discourse.codecombat.com/u/123hi123)
#### Post date: [February 5, 2019, 12:49am UTC](https://discourse.codecombat.com/t/i-need-help-with-village-warder/17375/2 "2019-02-05T00:49:00Z")

</div>

you need to put

```python
if hero.isReady("cleave"):
    cleave

```

somewhere in

```python
def findAndCleaveEnemy():
    # Define a function to cleave enemies (but only when the ability is ready).
    if enemy:
        hero.attack(enemy)
    enemy = hero.findNearestEnemy()
    enemy = hero.findNearestEnemy()

    hero.cleave(enemy)
    pass

```

also, you don’t need to repeat `enemy = hero.findNearestEnemy()` twice every time

---

<div class="post-metadata">

### Author: ![Luke10](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/luke10/32/19892_2.png) [@Luke10](https://discourse.codecombat.com/u/Luke10)
#### Post date: [February 6, 2019, 12:32am UTC](https://discourse.codecombat.com/t/i-need-help-with-village-warder/17375/3 "2019-02-06T00:32:05Z")

</div>

Also in the future, please format you code according to the [FAQ](https://discourse.codecombat.com/faq).

---

<div class="post-metadata">

### Author: ![PinkiePie](https://avatars.discourse-cdn.com/v4/letter/p/439d5e/32.png) [@PinkiePie](https://discourse.codecombat.com/u/PinkiePie)
#### Post date: [February 6, 2019, 1:29am UTC](https://discourse.codecombat.com/t/i-need-help-with-village-warder/17375/4 "2019-02-06T01:29:52Z")

</div>

def findAndAttackEnemy():  
enemy = hero.findNearestEnemy()  
enemy = hero.findNearestEnemy()

hero.attack(enemy)

def findAndCleaveEnemy():  
# Define a function to cleave enemies (but only when the ability is ready).  
ready = hero.isReady(“cleave”)  
hero.attack(enemy)  
ready = hero.isReady(“cleave”)

```
enemy = hero.findNearestEnemy()
enemy = hero.findNearestEnemy()
hero.attack(enemy)
hero.cleave(enemy)

```

while True:  
# Move to the patrol point, cleave, and attack.  
hero.moveXY(35, 34)  
findAndCleaveEnemy()  
findAndAttackEnemy()

hero.moveXY(60, 31)  
findAndCleaveEnemy()  
findAndAttackEnemy()

It says it is wrong, but what do I need to fix?

---

<div class="post-metadata">

### Author: ![Chaboi\_3000](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chaboi_3000/32/48486_2.png) [@Chaboi\_3000](https://discourse.codecombat.com/u/Chaboi_3000)
#### Post date: [February 6, 2019, 6:21am UTC](https://discourse.codecombat.com/t/i-need-help-with-village-warder/17375/5 "2019-02-06T06:21:52Z")

</div>

Please learn to post your code correctly. The way it is now, we can’t see the structure. Help us help you. It’s very easy to do and just takes a tiny bit of effort. Please read this topic and format your code again correctly

> [@\[Essentials\] How To Post/Format Your Code Correctly](https://discourse.codecombat.com/t/essentials-how-to-post-format-your-code-correctly/15521):
>
> Formatting your code before posting code is essential to our community, and if you don’t we might not be able to help frowning Everyone must know how to format ALL of your code properly. It’s really easy and only requires a very small amount of effort. To post your code from the game , use the \</\> button or it won’t format properly. When you click the \</\> button, the following will appear: Please paste ALL …

---

<div class="post-metadata">

### Author: ![Mocharug](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/mocharug/32/10670_2.png) [@Mocharug](https://discourse.codecombat.com/u/Mocharug)
#### Post date: [May 15, 2020, 1:23pm UTC](https://discourse.codecombat.com/t/i-need-help-with-village-warder/17375/6 "2020-05-15T13:23:20Z")

</div>

I also am needing help, i dont really know how to post this with the correct formatting, but its in JavaScript.

function findAndAttackEnemy() {  
var enemy = hero.findNearestEnemy();  
if (enemy) {  
hero.attack(enemy);  
}  
}  
function findAndCleaveEnemy() {  
var enemy = hero.findNearestEnemy();  
if (enemy) {

```
}
    if (hero.isReady("cleave")) {
        
    }
        hero.cleave(enemy);

```

}

while (true) {  
hero.moveXY(35, 34);  
findAndCleaveEnemy();  
findAndAttackEnemy();

```
hero.moveXY(60, 31);
findAndCleaveEnemy();
findAndCleaveEnemy();

```

}

---

<div class="post-metadata">

### Author: ![Deadpool198](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/deadpool198/32/16753_2.png) [@Deadpool198](https://discourse.codecombat.com/u/Deadpool198)
#### Post date: [May 15, 2020, 2:21pm UTC](https://discourse.codecombat.com/t/i-need-help-with-village-warder/17375/7 "2020-05-15T14:21:50Z")

</div>

Hi @Mocharug, welcome to the codecombat discourse! 🎉  
Please could you format your code so I can see the indents (the gaps at the start of each line). Read this topic for an explanation of how to do it:

> [@\[Essentials\] How To Post/Format Your Code Correctly](https://discourse.codecombat.com/t/essentials-how-to-post-format-your-code-correctly/15521):
>
> Formatting your code before posting code is essential to our community, and if you don’t we might not be able to help frowning Everyone must know how to format ALL of your code properly. It’s really easy and only requires a very small amount of effort. To post your code from the game , use the \</\> button or it won’t format properly. When you click the \</\> button, the following will appear: Please paste ALL …

Thanks  
Danny
