Level: The Agrippa Defense B


#1

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)

#2

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


#3

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


#4

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


#5

question is then is how do you fix it?


#6

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