Leave it to Cleaver help? [SOLVED]


#1
def cleaveWhenClose(target):
    if hero.distanceTo(target) < 5:
        ready = hero.isReady("cleave")
        hero.cleave(target)
    else:
        hero.attack(target)
while True:
    target = hero.findNearestEnemy()
    if target:
        cleaveWhenClose(target)

This is the code I’m using. It leaves 2 enemies left and the level is failed. I honestly don’t know what I’ve done wrong lol


#2

In your function, you unnecessarily define a variable “ready” and then don’t even call it anywhere. This line should be removed and replaced with an if conditional, if hero.isReady("cleave"): and then tab everything over accordingly.


#3

I didn’t even notice that.
This is my new code

def cleaveWhenClose(target):
    if hero.distanceTo(target) < 5:
        if hero.isReady("cleave"):
            hero.cleave(target)
    else:
        hero.attack(target)
while True:
    target = hero.findNearestEnemy()
    if target:
        cleaveWhenClose(target)

it still leaves a couple of enemies left


#4

…I’ve been stuck on this level for 2 days…

and all i had to do was move the else hero.attack(target)over.