Hit and Freeze - hero always dies, no error messages in code?

Can someone figure out what I’m going wrong? Thanks!

# You are trapped. Don't move, it'll be painful.

# This function checks if the enemy is in your attack range.
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.
    enemy = hero.findNearestEnemy()
    canAttack = inAttackRange(enemy)
    # Call inAttackRange(enemy), with the enemy as the argument
    # and save the result in the variable canAttack.
    inAttackRange(enemy)
    # If the result stored in canAttack is True, then attack!
    if canAttack:
        hero.attack(enemy)
    pass

#You are using “PROGRAMMATICON 1”.
#This level requires “PROGRAMMATICON 2”.
#Equip your hero with “PROGRAMMATICON 2” or more health.

2 Likes

Try to use a better sword. Long sword for example. You need to kill ogres with one hit.

1 Like

Equipping PROGRAMMATICON 2 resolved it. Thank you! I can’t believe it was something as simple as that…

1 Like

Have you completed it with the Sharpen Sword?

Programmticon II is required for “if-else”. I’ll add it to the required items for this level.

1 Like