Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Mountain Mercernaries Infinite Loop

The level keeps saying I have an infinite loop. I think it has something to do with picking up the coins, but I don’t see what’s wrong with it. Can somebody help me?

# Gather coins to summon soldiers and have them attack the enemy.

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

Hi @Poseidon and welcome to the forum! You are not incrementing soldierIndex, so the look is always looking for soldiers[0], be he alive or dead.