# \[SOLVED\] Mountain mercenaries Level help

**URL:** <https://discourse.codecombat.com/t/solved-mountain-mercenaries-level-help/19667>\
**Category:** Level Help\
**Created:** [November 18, 2019, 11:59pm UTC](https://discourse.codecombat.com/t/solved-mountain-mercenaries-level-help/19667 "2019-11-18T23:59:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thatguy\_youknow0](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/thatguy_youknow0/32/11040_2.png) [@Thatguy\_youknow0](https://discourse.codecombat.com/u/Thatguy_youknow0)\
**Post date:** [November 18, 2019, 11:59pm UTC](https://discourse.codecombat.com/t/solved-mountain-mercenaries-level-help/19667/1 "2019-11-18T23:59:32Z")

</div>

```python
# 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()
    hero.move(coin.pos)
    
    # If you have funds for a soldier, summon one.
    if hero.gold > hero.costOf("soldier"):
        hero.summon("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.
        hero.command(soldier, "attack", enemy)
        # Use the 'attack' command to make your soldiers attack.
        #hero.command(soldier, "attack", enemy)

```

---

<div class="post-metadata">

**Author:** ![Thatguy\_youknow0](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/thatguy_youknow0/32/11040_2.png) [@Thatguy\_youknow0](https://discourse.codecombat.com/u/Thatguy_youknow0)\
**Post date:** [November 18, 2019, 11:59pm UTC](https://discourse.codecombat.com/t/solved-mountain-mercenaries-level-help/19667/2 "2019-11-18T23:59:57Z")

</div>

No error messages, I just don’t know what to do.

---

<div class="post-metadata">

**Author:** ![ninjagoo](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ninjagoo/32/10666_2.png) [@ninjagoo](https://discourse.codecombat.com/u/ninjagoo)\
**Post date:** [November 19, 2019, 1:04am UTC](https://discourse.codecombat.com/t/solved-mountain-mercenaries-level-help/19667/3 "2019-11-19T01:04:35Z")

</div>

loop through your soldiers, and use if coin

---

<div class="post-metadata">

**Author:** ![Deadpool198](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/deadpool198/32/16753_2.png) [@Deadpool198](https://discourse.codecombat.com/u/Deadpool198)\
**Post date:** [November 19, 2019, 10:34am UTC](https://discourse.codecombat.com/t/solved-mountain-mercenaries-level-help/19667/4 "2019-11-19T10:34:53Z")

</div>

Just to add to what ninjagoo said you have to loop over you soldiers like you did in earlier Sarven desert coin levels. E.g. while coinIndex \< len(coins): …etc.
