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!
Can you please format your code correctly?
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.
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.
the thing is that if i use def it calls it an error
i’m done with it thanks!
This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.