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

if hero.isReady("cleave"):
    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).
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?

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

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

}

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

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

}

Hi @Mocharug, welcome to the codecombat discourse! :tada:
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