I’ve been trying to get my allies to attack the witch first, then the nearest enemy, but no matter what I try, They kill the witch, then stay still while the rest of the ogres clobber them. Here’s my code:
for friend in self.findFriends():
witch = friend.findNearest(self.findByType("witch"))
if witch:
self.command(friend, "attack", witch)
else:
target = friend.findNearestEnemy()
if target:
self.command(friend, "attack", target)
Here, I’ll post my whole code. That might make a difference.
loop:
for friend in self.findFriends():
witch = friend.findNearest(self.findByType("witch"))
if witch:
self.command(friend, "attack", witch)
else:
target = friend.findNearestEnemy()
if target:
self.command(friend, "attack", target)
while self.pos.x < 69:
self.move({'x':69, 'y':15})
self.say("Hi!")
while self.pos.x > 37:
self.move({'x':37, 'y':16})
self.say("Bye!")
for i in range(3):
enemy = self.findNearest(self.findByType("catapult"))
if enemy:
self.attack(enemy)
self.say("Hi!")
while self.pos.x > 37:
self.move({'x':37, 'y':16})
while self.pos.x < 78:
self.move({'x':78, 'y':14})
trotod is right. A helpful rule of thumb is to make sure that you only take one action each run through your loop so that you are always responsive. A second rule (which you are following) is to always tell your minions what to do first thing, so that they act on the most recent information.