Mountain Mercenaries: Only one soldier attacking


#1

So. I’ve read through the other posts and nobody seems to have the same problem I’m having. On top of lagging, only one soldier ever goes to attack the enemy at once. Code is as follows:

while True:
    # Move to the nearest coin.
    # Use move instead of moveXY so you can command constantly.
    coin = hero.findNearest(hero.findItems())
    hero.move(coin.pos)
    # If you have funds for a soldier, summon one.
    if hero.gold > hero.costOf("soldier"):
        hero.summon("soldier")
    enemies = hero.findEnemies()
    enemy = hero.findNearest(enemies)
    if enemy:
        # Loop over all your soldiers and order them to attack.
        soldiers = hero.findFriends()
        soldierIndex = 0
        soldier = soldiers[soldierIndex]
        while soldierIndex < len(soldiers):
            hero.command(soldier, "attack", enemy)
        # Use the 'attack' command to make your soldiers attack.
            soldierIndex += 1

What am I doing wrong here?


#2

What does the soldier variable reference each time in the loop?


#3

The soldier variable references soldier #(whatever soldierIndex is at) and by adding a ‘say’ command to that loop, I can see that soldierIndex is cycling as intended. So, I still don’t see what’s up.


#4

Look at the soldier variable once again.

What is it being assigned to? Does it change?