[SOLVED] What's wrong with my code? Python

while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        if hero.isReady("cleave"):
            hero.cleave()
        else:
            hero.attack()
            hero.shield()
            hero.attack()
        pass
    pass

I really don’t know what’s wrong. The error message I get says “Attack’s argument target should have type object, but got null. Target is null. Is there always a target to attack? (Use if)”

This is on the Kithgard Brawl.

1 Like

hero.attack needs to attack something. The proper way would be to write: hero.attack(enemy) in this case

Thanks! _________________________

1 Like

My code is written like this:
while True:
enemy = hero.findNearestEnemy()
if hero.isReady(“cleave”):
hero.cleave(enemy)
else:
enemy = hero.findNearestEnemy()
hero.attack(enemy)

and i got the same error

You need to check whether there is an enemy. Otherwise, if here isn’t an enemy what are you targeting?