# Hit and freeze HELP

It’s great that you finished the level but please don’t post finished code or final solutions. The purpose of this board is to help people figure out the solutions themselves so they can learn. Simply providing solutions/code is counterproductive to the main goal. Thank you.

I don’t understand it

Try calling the function in line 18, exactly the way it’s named in line 4.

Hi i am stuck on this can u help me ???
here is my code

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

and then it shows this

In your code (not the function, the code) you haven’t properly defined enemy. And when you define the `canAttack` variable, make sure that the name of the function is exactly the way it appears in line 4.

Also, if you have any more trouble, try reading through some of the other posts in this thread. There’s more than enough information here for you to finish the level.

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

Hi @Ryan_Zhong, welcome to the CodeCombat discourse!

It really helps me read your code, especially because your problem could be to do with indentation, (the gaps between lines).
Thanks
Danny

hi I need help with my code it keep saying true not define,

``````def inAttackRange(enemy):
distance = hero.distanceTo(enemy)
if distance <= 3:
return True
else:
return False

while True:
enemy = hero.findNearestEnemy()
canAttack = inAttackRange
if canAttack == true:
hero.attack(enemy)
pass

``````

pls help me improve it

All you have to do is remove this part.

but then the hero die and remaines 4 ogres

Does line 12 need to be canAttack = inAttackRange(enemy)?

ya that’s what i think

i made a few changes and now it says I dont have a item equiped with attackRange skill

true need to be capitalized

``````if canAttack() == True:
# do stuff
``````

Or just

``````if canAttack:
``````

yea that woks true (20)

if i put just put canAttack the hero attack but remains 4 ogres

The question I have is, how do I defeat the four ogres remaining

oh I actually did it but I equiped something else with it