Hit and freeze HELP

I don’t understand it


Please help me

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

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.
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.

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()
# 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! :tada:
Please could you read this topic to learn how to format your code on 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