The Agrippa Defense help?

loop:
enemy = self.findNearestEnemy()
if enemy:
    self.distanceTo(enemy)
    if self.distanceTo(enemy) < 5:
        if self.isReady("cleave"):
            self.cleave(enemy)
else:
    self.attack(enemy)

I get the error “Target is null, is there always a target (use if)?” Which is why I put the “If enemy:” but my char just stands there and dies

if enemy:
    #do something
else: #there is no enemy
    self.attack(enemy)

See the error?

You have to indent your else more.

To be totally honest with you, I don’t see the error, if I use if enemy:, that basically means that you need to do everything under it right? I tried for 15 mins now and I couldn’t do it still.

@Subv :
your code asks “is there a enemy” if yes, the code will run the if enemy. If there is no enemy, if enemy isnt true, and therefore the code jumps to else: and there is the problem. else mens, there is no enemy, if there would be, if would be true. So your hero cannt attack an “enemy” because there is none.
change your code like this:

loop:
enemy = self.findNearestEnemy()
if enemy: # attack the enemy
    self.distanceTo(enemy)
    if self.distanceTo(enemy) < 5:
        if self.isReady("cleave"):
            self.cleave(enemy)
else:
    # do sth when no enemy is there, whatever u are supposed to do

u understand what i mean?