Hit and freeze help!

i cant define ANYTHING WHAT IS GOING ON!!!

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

Welcome to the forum! This is a family-friendly place where coders can share bugs, ask for help on any CodeCombat level (donâ€™t forget to post your code correctly), or just hang out with other coders. But before you proceed, please check out our guidelines: this topic.
Have a great time!

Try having a distance of 4 instead of 3. Thatâ€™s what I did, and it was faster.

No, youâ€™re not allowed to. Itâ€™s cheating for others because theyâ€™re not figuring it out themselves. Just drop hints, donâ€™t give the whole code, please.

ok,

I got a hint, use distanceTo.

1 Like

First you need to find the nearest enemy and define it as enemy. Then you need to â€śCall inAttackRange(enemy), with the enemy as the argument and save the result in the variable canAttack.â€ť After that, if canAttack is true, then attack enemy.

1 Like

the thing is that if i use def it calls it an error

iâ€™m done with it thanks!

1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.