What´s wrong with my code?


#1

Can someone tell me whats wrong with my code in code combat? i get the “cannot read property “start” or undefined” error.
Thanks for your help

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


#2

not:

inAttackRange(enemigo) = canAttack

     return True
     hero.attack(enemigo)

but:

canAttack=inAttackRange(enemigo)
if canAttack:
   hero.attack(enemigo)