# Mountain Mercenaries Help Required, PLEASE HELP!

**URL:** <https://discourse.codecombat.com/t/mountain-mercenaries-help-required-please-help/4998>\
**Category:** Uncategorized\
**Created:** [September 21, 2015, 7:33am UTC](https://discourse.codecombat.com/t/mountain-mercenaries-help-required-please-help/4998 "2015-09-21T07:33:49Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Combat\_Gaming](https://avatars.discourse-cdn.com/v4/letter/c/6bbea6/32.png) [@Combat\_Gaming](https://discourse.codecombat.com/u/Combat_Gaming)\
**Post date:** [September 21, 2015, 7:33am UTC](https://discourse.codecombat.com/t/mountain-mercenaries-help-required-please-help/4998/1 "2015-09-21T07:33:49Z")

</div>

Hi guys, I’m not exactly new around here but I have a problem with Mountain Mercenaries. It keeps saying: Line19 Your Hero Placerholder needs something to command.  
Every reply, help and command are thanked.  
My Code -

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

> loop:  
> # Move to the nearest coin.  
> # Use move instead of moveXY so you can command constantly.  
> self.say(“I need coins!”)

> ```
> # If you have funds for a soldier, summon one.
> if self.gold > self.costOf("soldier"):
> self.say("I should summon something here!")
> 
> ```

> ```
> enemy = self.findNearest(self.findEnemies())
> if enemy:
> # Loop over all your soldiers and order them to attack.
> soldiers = self.findFriends()
> soldierIndex = 0
> soldier = soldiers[soldierIndex]
> self.summon("soldier")
> self.command(soldier, "attack", enemy)
> 
> ```

> ```
> # Use the 'attack' command to make your soldiers attack.
> #self.command(soldier, "attack", enemy)
> 
> ```

---

<div class="post-metadata">

**Author:** ![J\_F\_B\_M](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/j_f_b_m/32/2756_2.png) [@J\_F\_B\_M](https://discourse.codecombat.com/u/J_F_B_M)\
**Post date:** [September 21, 2015, 11:06am UTC](https://discourse.codecombat.com/t/mountain-mercenaries-help-required-please-help/4998/2 "2015-09-21T11:06:09Z")

</div>

It is clearly written in the FAQ how to

> [@FAQ - Check Before Posting](https://discourse.codecombat.com/t/faq-check-before-posting/1027/1):
>
> Post your code with radiant, harmonious formatting

How do people still manage to use block-_ **quotes** _?

* * *

Sorry for the little rant, here is your problem:

```python
soldiers = self.findFriends() #Is currently empty, no friends spawned yet
soldierIndex = 0
soldier = soldiers[soldierIndex] #Tries to get the first entry of an empty list, soldier = None
self.summon("soldier") #If you would now call findFriends(), you would get a list with one entry
self.command(soldier, "attack", enemy) #As soldier is None your code fails

```

You should solve the level as intended. There is a line in the default-code that says `"I should summon something here!"` Use this place to summon your soldiers, it works best.

---

<div class="post-metadata">

**Author:** ![Combat\_Gaming](https://avatars.discourse-cdn.com/v4/letter/c/6bbea6/32.png) [@Combat\_Gaming](https://discourse.codecombat.com/u/Combat_Gaming)\
**Post date:** [September 22, 2015, 11:50am UTC](https://discourse.codecombat.com/t/mountain-mercenaries-help-required-please-help/4998/4 "2015-09-22T11:50:39Z")

</div>

I did this but my soldiers won’t attack anything.

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

> loop:  
> # Move to the nearest coin.  
> # Use move instead of moveXY so you can command constantly.  
> self.say(“I need coins!”)

> ```
> # If you have funds for a soldier, summon one.
> if self.gold > self.costOf("soldier"):
> self.summon("soldier")
> 
> ```

> ```
> enemy = self.findNearest(self.findEnemies())
> if enemy:
> # Loop over all your soldiers and order them to attack.
> soldiers = self.findFriends()
> soldierIndex = 0
> soldier = None
> soldierIndex += 1
> self.command(soldier, "attack", enemy)
> 
> ```

> ```
> # Use the 'attack' command to make your soldiers attack.
> #self.command(soldier, "attack", enemy)
> 
> ```

---

<div class="post-metadata">

**Author:** ![GundericusTheMighty](https://avatars.discourse-cdn.com/v4/letter/g/bbce88/32.png) [@GundericusTheMighty](https://discourse.codecombat.com/u/GundericusTheMighty)\
**Post date:** [September 22, 2015, 1:35pm UTC](https://discourse.codecombat.com/t/mountain-mercenaries-help-required-please-help/4998/5 "2015-09-22T13:35:56Z")

</div>

Once you have a `loop:`, everything in the loop needs to be indented by one tab or four spaces. Lines 2-4 are not.

You have a problem with your `if enemy:` section. You tell it to define `soldiers` as all friends, then `soldierIndex` as 0 and `soldier` as null, then add one to `soldierIndex` without having used either `soldierIndex` it or `soldiers`. At this point, you attempt to command a soldier you defined as `none`. This doesn’t work. You need a while- or for-loop.

Also, it’s going to be hard to summon enough soldiers without gathering coins. Replace `self.say("I need coins!")` with code to find coins.

---

<div class="post-metadata">

**Author:** ![JohnnyRobotic](https://avatars.discourse-cdn.com/v4/letter/j/c67d28/32.png) [@JohnnyRobotic](https://discourse.codecombat.com/u/JohnnyRobotic)\
**Post date:** [September 24, 2015, 6:54pm UTC](https://discourse.codecombat.com/t/mountain-mercenaries-help-required-please-help/4998/6 "2015-09-24T18:54:54Z")

</div>

I got mine to work using this code below. The kicker was using move and not moveXY and on top of that don’t try to use an array for coins, if you do you’ll waste time going from coin to coin instead of just grabbing what is closest.

[redacted, we don’t post correct code]

---

<div class="post-metadata">

**Author:** ![GundericusTheMighty](https://avatars.discourse-cdn.com/v4/letter/g/bbce88/32.png) [@GundericusTheMighty](https://discourse.codecombat.com/u/GundericusTheMighty)\
**Post date:** [September 25, 2015, 3:06pm UTC](https://discourse.codecombat.com/t/mountain-mercenaries-help-required-please-help/4998/7 "2015-09-25T15:06:47Z")

</div>

Please don’t post correct code–it takes the whole point out of the game.

---

<div class="post-metadata">

**Author:** ![csd](https://avatars.discourse-cdn.com/v4/letter/c/46a35a/32.png) [@csd](https://discourse.codecombat.com/u/csd)\
**Post date:** [October 26, 2015, 9:07pm UTC](https://discourse.codecombat.com/t/mountain-mercenaries-help-required-please-help/4998/8 "2015-10-26T21:07:08Z")

</div>

You should use flags and attack. You can summon if there is a black flag and move for the green. You will also need to attack.

---

<div class="post-metadata">

**Author:** ![Neel\_Sharma](https://avatars.discourse-cdn.com/v4/letter/n/e495f1/32.png) [@Neel\_Sharma](https://discourse.codecombat.com/u/Neel_Sharma)\
**Post date:** [March 26, 2016, 10:01pm UTC](https://discourse.codecombat.com/t/mountain-mercenaries-help-required-please-help/4998/9 "2016-03-26T22:01:08Z")

</div>

I agree. Could someone just hide the code so no one uses it?

---

<div class="post-metadata">

**Author:** ![GundericusTheMighty](https://avatars.discourse-cdn.com/v4/letter/g/bbce88/32.png) [@GundericusTheMighty](https://discourse.codecombat.com/u/GundericusTheMighty)\
**Post date:** [March 26, 2016, 11:50pm UTC](https://discourse.codecombat.com/t/mountain-mercenaries-help-required-please-help/4998/10 "2016-03-26T23:50:13Z")

</div>

I flagged it for moderation. The guys in charge should fix the problem. Have a great day!

---

<div class="post-metadata">

**Author:** ![Bobesh](https://avatars.discourse-cdn.com/v4/letter/b/f6c823/32.png) [@Bobesh](https://discourse.codecombat.com/u/Bobesh)\
**Post date:** [June 20, 2016, 2:20pm UTC](https://discourse.codecombat.com/t/mountain-mercenaries-help-required-please-help/4998/11 "2016-06-20T14:20:15Z")

</div>

Hi, I have similar problems. My soliders are just staying like my hero. Hero do not collect coins and soldiers are not attacking. Every help is welcomed.

```
 `while True:
    # Move to the nearest coin.
    # Use move instead of moveXY so you can command constantly.
    hero.say("I need coins!")
    if hero.gold < hero.costOf("soldier"):
        while hero.gold < hero.costOf("soldier"):
            items = hero.findItems()
            nearest = hero.findNearest(items)
            if nearest:
                hero.say(hero.distanceTo(nearest))
                hero.move(nearest.pos)
# If you have funds for a soldier, summon one.
    if hero.gold > hero.costOf("soldier"):
        hero.say("I should summon something here!")
        hero.summon("soldier")

    enemy = hero.findNearest(hero.findEnemies())
    if enemy:
        # Loop over all your soldiers and order them to attack.
        soldiers = hero.findFriends()
        soldierIndex = 0
        if soldiers:
            hero.say("soldiers")
            while len(soldiers) > soldierIndex:
                soldier = soldiers[soldierIndex]
                if soldier:
                    hero.say("found one")
                    hero.command(soldier, "attack", enemy)
                    soldierIndex += 1

```

`

---

<div class="post-metadata">

**Author:** ![Adam\_King](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/adam_king/32/2705_2.png) [@Adam\_King](https://discourse.codecombat.com/u/Adam_King)\
**Post date:** [January 11, 2018, 11:46pm UTC](https://discourse.codecombat.com/t/mountain-mercenaries-help-required-please-help/4998/12 "2018-01-11T23:46:27Z")

</div>

All I did was remove all `hero.say()` commands

---

<div class="post-metadata">

**Author:** ![kyay10](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/kyay10/32/7337_2.png) [@kyay10](https://discourse.codecombat.com/u/kyay10)\
**Post date:** [January 12, 2018, 12:52am UTC](https://discourse.codecombat.com/t/mountain-mercenaries-help-required-please-help/4998/13 "2018-01-12T00:52:01Z")

</div>

first remove all of the say commands, you don’t need them, then change this

> [@Bobesh](#):
>
> ```
> if soldiers:
> hero.say("soldiers")
> while len(soldiers) > soldierIndex:
> soldier = soldiers[soldierIndex]
> if soldier:
> hero.say("found one")
> hero.command(soldier, "attack", enemy)
> soldierIndex += 1
> 
> ```

to this

```python
        if soldiers:
            hero.say("soldiers")
            while len(soldiers) > soldierIndex:
                soldier = soldiers[soldierIndex]
                if soldier:
                    hero.say("found one")
                    hero.command(soldier, "attack", enemy)
                soldierIndex += 1

```

because you need to increase the index no matter if you found a soldier or not
