How to do the hit and freeze level

I dont understand how to keep still

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.
inAttackRange(enemy)
canAttack=
# If the result stored in canAttack is True, then attack!
if “true”:
hero.attack(enemy)
else:
pass

Welcome to the discourse @Student_Suraj_Soni! :partying_face: before you continue please read this topic on how to post your code correctly.

2 Likes