Level: The Agrippa Defense B

What’s wrong with the code?

def enemyInRange(enemy):
    # Return true if the enemy is less than 5 units away.
    if enemy < 5:
        return True

def cleaveOrAttack(enemy):
    if hero.isReady('cleave'):
        hero.cleave(enemy)
    else:
        hero.attack(enemy)

while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        # Check the distance of the enemy by calling enemyInRange.
        if enemyInRange(enemy):
            cleaveOrAttack(enemy)

I don’t see what you Returned True for. Do something with the True perhaps?

You forgot to check enemy’s distance when defining the function enemyInRange() :wink:

1 Like

you use true when it says “while True: …”

question is then is how do you fix it?

The problem is with if enemy < 5 : it’s meaningless this way. It should be if hero.distanceTo(enemy)