Leave it to Cleaver Help

Hello, I’ve been stuck on this for a few hours and am trying to figure out what’s going on with my code. I’ve been able to get the knight to cleave, but can’t get it to attack anything (in the else statement). Should it not just default to the else statement if the if statement isn’t true?

function cleaveWhenClose(target) {
    if(hero.distanceTo(target) > 5) {
        if (hero.isReady, ("cleave")) {
            hero.cleave(target);
        }
        else {
            hero.attack(target);
        }
    }
}

// This code is not part of the function.
while(true) {
    var enemy = hero.findNearestEnemy();
    if(enemy) {
        cleaveWhenClose(enemy);
        }
}

I know it’s gotta be something silly I’ve done, but can’t figure out where I went wrong. thanks!

1 Like

There is no hero.isReady,
The correct way to write this is: (hero.isReady("cleave"))
Also, I recommend only cleaving when close to enemy: hero.distanceTo(target) < 5

3 Likes

That worked perfectly, thank you so much!!

2 Likes