Mountain Mercenaries help! (PYTHON)

Help!!! I can’t pass this level! Is there anything wrong?:

# 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.
    coin = hero.findNearestItem()
    # 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):
        if soldier:
            # Use the 'attack' command to make your soldiers attack.
            #hero.command(soldier, "attack", enemy)
            hero.command(soldier, "attack", enemy)
            soldierIndex += 1

Can someone help me?:tired_face::tired_face::tired_face:

You’re close, but you have several mistakes.
You should get into the habit of always checking if there’s something before you do anything with it. For example, you’re missing an if-statement when you’re collecting a coin.
You’re targeting only the 0th index of soldiers, not everything. Why did you comment out the while loop? Remove the comment on the line.
3) Put the soldier = soldiers[soldierIndex] inside the while loop mentioned above. Otherwise you’re only specifying soldiers[0]


Thanks!!! I just passed the level! thx

1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.