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!
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 enemy < 10: hero.attack(enemy)
I’m not sure what I’m doing wrong. Hero won’t attack.