Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

When i run this code my hero will stay in one place and attack dead enemies and will cleave when there is no enimiess

def cleaveWhenClose(target):
if hero.distanceTo(target) < 5:
pass
hero.attack(enemy)

    if hero.isReady("cleave"):
        hero.cleave(enemy)
    
    
    else:
        hero.attack(enemy)

while True:
enemy = hero.findNearestEnemy()
if enemy:

    cleaveWhenClose(enemy)

Welcome back!

Please format your code correctly as it says in this
And what level is this?

Lydia

In your cleaveWhenClose() function, you are directly attacking an enemy even if there is no enemy, so use an if statement checking for an enemy. You should probably cleave and attack target instead of enemy.