Ok so I am confused, whenever I try to make the if (dist > 10): command work and it isn’t working, when I do the correction it wants me to it fails with the Ran Out of Time failure text; if anyone wants to see my code here it is:
# If you try to attack a distant enemy, your hero will charge toward it, ignoring all flags.
# You'll need to make sure you only attack enemies who are close to you!
while True:
flag = hero.findFlag()
enemy = hero.findNearestEnemy()
if flag:
# Pick up the flag.
hero.pickUpFlag(flag)
hero.say("I should pick up the flag.")
elif enemy:
# Only attack if the enemy distance is < 10 meters
if (dist < 10):
hero.attack(enemy)
and I can attach a screenshot if anyone needs me to as well I can attatch it later on…
Have you defined dist yet? You have to define dist first in order for your code to work.
So you would do hero.distanceTo(enemy) in the very beginning of your while-True loop.
Or you could do it the way PeterPalov did it.
Lydia
ok so I am trying these right now I have yet to try it but here is my current code: (also sorry for late reply)
# If you try to attack a distant enemy, your hero will charge toward it, ignoring all flags.
# You'll need to make sure you only attack enemies who are close to you!
while True:
flag = hero.findFlag()
enemy = hero.findNearestEnemy()
if flag:
# Pick up the flag.
hero.pickUpFlag(flag)
hero.say("I should pick up the flag.")
elif enemy:
# Only attack if the enemy distance is < 10 meters
dist = hero.distanceTo(enemy)
if dist < 10
I will try these after another reply since I am really busy lately
also edit: just noticed there is an error