# 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 enemy:
(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.
var canAttack = inAttackRange(enemy);
# Call inAttackRange(enemy), with the enemy as the argument
# and save the result in the variable canAttack.
inAttackRange(enemy)}
# If the result stored in canAttack is true, then attack!
hero.attack(enemy);
Are you coding on Python or JavaScript?
oh your Javascript 2000000000000
it looks like java 2000
python
PeterPalov
I can help you then 2000
If your a beginner let’s not make it too confusing
i am a beginner 20000000000000000000000
why are you adding ;
to your code?
you only use ;'s in Javascript
and you should do this
Thank you, I did…
show me your code and I’ll see if you did it correctly
You don’t need to use “var” or }'s in python either.
yeah 2000000000000000000
To sum up what everyone here has said, don’t use var, }, or ; if you are using Python. Also, with the if enemy
statement, putting (distance <= 3)
doesn’t really do anything. Instead, you want to put if enemy and hero.distanceTo(enemy) <= 3:
Also, somewhere, you need to say what the term enemy
actually means. I strongly suggest replacing var canAttack = inAttackRange(enemy);
with enemy = hero.findNearestEnemy()
.
-Gray