Hello, I’m stuck on the writing party level! I can’t figure out how to make all of my soldiers and archers move right and attack at the same time?
Here’s my code:
# Command your troops to move east and attack any ogres they see.
# Use for-loops and findFriends.
# You can use findNearestEnemy() on your soldiers to get their nearest enemy instead of yours.
loop:
friends = self.findFriends()
enemies = friend.findEnemies()
enemy = friend.findNearest(enemies)
pos = friend.pos
newX = pos.x + 10
newY = pos.y
if enemy:
self.command(friends, "attack", enemy)
else:
self.command(friends, "move", {"x": newX, "y": newY})
But when I try this it says “Hero placeholder needs something to command”.
But when I try this code:
# Command your troops to move east and attack any ogres they see.
# Use for-loops and findFriends.
# You can use findNearestEnemy() on your soldiers to get their nearest enemy instead of yours.
loop:
friends = self.findFriends()
enemies = friend.findEnemies()
enemy = friend.findNearest(enemies)
pos = friend.pos
newX = pos.x + 10
newY = pos.y
if enemy:
self.command(friend, "attack", enemy)
else:
self.command(friend, "move", {"x": newX, "y": newY})
Only one soldier/archer moves at a time. The difference is:
if enemy:
self.command(friends, "attack", enemy)
else:
self.command(friends, "move", {"x": newX, "y": newY})
and:
if enemy:
self.command(friend, "attack", enemy)
else:
self.command(friend, "move", {"x": newX, "y": newY})
Is there a way to make all of them move at once?