# I need help with Village Warder

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()

you need to put

cleave

somewhere in

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

Also in the future, please format you code according to the FAQ.

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).
hero.attack(enemy)

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?

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

1 Like

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) {

}

}
hero.cleave(enemy);

}

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

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

}

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:

Thanks
Danny