# \[SOLVED\] Python - Mountain Mercenaries

**URL:** <https://discourse.codecombat.com/t/solved-python-mountain-mercenaries/30080>\
**Category:** Level Help\
**Created:** [August 19, 2021, 10:15am UTC](https://discourse.codecombat.com/t/solved-python-mountain-mercenaries/30080 "2021-08-19T10:15:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Golfan](https://avatars.discourse-cdn.com/v4/letter/g/f07891/32.png) [@Golfan](https://discourse.codecombat.com/u/Golfan)\
**Post date:** [August 19, 2021, 10:15am UTC](https://discourse.codecombat.com/t/solved-python-mountain-mercenaries/30080/1 "2021-08-19T10:15:53Z")

</div>

Hello,

I don’t get it, my hero moves to the coin and summons alright, but will not command at all. Soldiers stay in place and get outnumbered and killed. Checked other topics but I don’t see what I’m doing wrong :

```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.
    item = hero.findNearest(hero.findItems())
    hero.move(item.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.
        while soldierIndex < len(soldiers):
            # Use the 'attack' command to make your soldiers attack.
            #hero.command(soldier, "attack", enemy)
            hero.command(soldier, "attack", enemy)
            soldierIndex += 1

```

Thanks for your help

---

<div class="post-metadata">

**Author:** ![Golfan](https://avatars.discourse-cdn.com/v4/letter/g/f07891/32.png) [@Golfan](https://discourse.codecombat.com/u/Golfan)\
**Post date:** [August 19, 2021, 10:46am UTC](https://discourse.codecombat.com/t/solved-python-mountain-mercenaries/30080/2 "2021-08-19T10:46:32Z")

</div>

Nevermind, found it myself,

The `soldier = soldiers[soldierIndex]` was missplaced

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/a/a9445509d1a758c41b5ddcddc8c8e20a5dedb67f.png) [@system](https://discourse.codecombat.com/u/system)\
**Post date:** [August 19, 2021, 10:46pm UTC](https://discourse.codecombat.com/t/solved-python-mountain-mercenaries/30080/3 "2021-08-19T22:46:41Z")

</div>

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