`hit and freeze

im on hit and freeze i cant figure it out. pls help. heres my code.```

def inAttackRange(enemy):
    distance = hero.distanceTo(enemy)
    # Almost all swords have attack range of 3.
    if distance <= 3:
        return True
    else:
        return False

# Attack ogres only when they're within reach.
while True:
    # Find the nearest enemy and store it in a variable.
    canAttack = hero.findNearestEnemy()
    # Call inAttackRange(enemy), with the enemy as the argument
    # and save the result in the variable canAttack.
    canAttack = inAttackRange(canAttack)
    # If the result stored in canAttack is True, then attack!
    if canAttack == true:
        hero.cleave(enemy)
    pass

Change that first canAttack variable to enemy.

Then change this canAttack parameter to enemy.

Then just check if cannAttack:

if canAttack:
    #attack not cleave

thank you. it worked

2 Likes

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.