# Mounatin Mercenaries Error

**URL:** <https://discourse.codecombat.com/t/mounatin-mercenaries-error/6174>\
**Category:** Uncategorized\
**Created:** [December 18, 2015, 5:47pm UTC](https://discourse.codecombat.com/t/mounatin-mercenaries-error/6174 "2015-12-18T17:47:45Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![J\_Butch](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/j_butch/32/3483_2.png) [@J\_Butch](https://discourse.codecombat.com/u/J_Butch)\
**Post date:** [December 18, 2015, 5:47pm UTC](https://discourse.codecombat.com/t/mounatin-mercenaries-error/6174/1 "2015-12-18T17:47:45Z")

</div>

HELP PLEASE

 ![](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/b/b8b388f3796b075a97abf275a02c75eb1be63ea4.PNG)

---

<div class="post-metadata">

**Author:** ![ChronistGilver](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chronistgilver/32/3778_2.png) [@ChronistGilver](https://discourse.codecombat.com/u/ChronistGilver)\
**Post date:** [December 18, 2015, 6:04pm UTC](https://discourse.codecombat.com/t/mounatin-mercenaries-error/6174/2 "2015-12-18T18:04:00Z")

</div>

Do you not remember how to use a while-loop? If you do not, replay Mad Maxer and Cloudrip Commander. Those levels should jog your memory.

---

<div class="post-metadata">

**Author:** ![J\_Butch](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/j_butch/32/3483_2.png) [@J\_Butch](https://discourse.codecombat.com/u/J_Butch)\
**Post date:** [December 18, 2015, 7:00pm UTC](https://discourse.codecombat.com/t/mounatin-mercenaries-error/6174/3 "2015-12-18T19:00:27Z")

</div>

That’s not the problem. the priblem is the “Line 19: tmp47[tmp48] is not a function”

---

<div class="post-metadata">

**Author:** ![ChronistGilver](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chronistgilver/32/3778_2.png) [@ChronistGilver](https://discourse.codecombat.com/u/ChronistGilver)\
**Post date:** [December 18, 2015, 7:05pm UTC](https://discourse.codecombat.com/t/mounatin-mercenaries-error/6174/4 "2015-12-18T19:05:58Z")

</div>

Hm, that’s no good. What glasses are you using?

---

<div class="post-metadata">

**Author:** ![J\_Butch](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/j_butch/32/3483_2.png) [@J\_Butch](https://discourse.codecombat.com/u/J_Butch)\
**Post date:** [December 18, 2015, 7:25pm UTC](https://discourse.codecombat.com/t/mounatin-mercenaries-error/6174/7 "2015-12-18T19:25:43Z")

</div>

Not the twilight i am using the fine wooden glasses. my bad

---

<div class="post-metadata">

**Author:** ![J\_Butch](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/j_butch/32/3483_2.png) [@J\_Butch](https://discourse.codecombat.com/u/J_Butch)\
**Post date:** [December 18, 2015, 7:41pm UTC](https://discourse.codecombat.com/t/mounatin-mercenaries-error/6174/8 "2015-12-18T19:41:45Z")

</div>

Ok now I am using the Twilight glasses and the error is fixed, but another popped up saying “Hero Placeholder needs somthing to command” on line 26: **self.command(“soldier”, “attack”, enemy)**

---

<div class="post-metadata">

**Author:** ![Serg](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/serg/32/3260_2.png) [@Serg](https://discourse.codecombat.com/u/Serg)\
**Post date:** [December 18, 2015, 8:06pm UTC](https://discourse.codecombat.com/t/mounatin-mercenaries-error/6174/9 "2015-12-18T20:06:04Z")

</div>

Can you post the entirety of your code?

To format your code correctly please press the `</>` button in the Discourse toolbar or surround your code with 3 back ticks.

```  
Code goes here.  
```

---

<div class="post-metadata">

**Author:** ![J\_Butch](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/j_butch/32/3483_2.png) [@J\_Butch](https://discourse.codecombat.com/u/J_Butch)\
**Post date:** [December 18, 2015, 8:14pm UTC](https://discourse.codecombat.com/t/mounatin-mercenaries-error/6174/10 "2015-12-18T20:14:48Z")

</div>

```python
# Gather coins to summon soldiers and have them attack the enemy
item = self.findNearestItem()
itemPos = item.pos
x = itemPos.x
y = itemPos.y

loop:
    # Move to the nearest coin.
    # Use move instead of moveXY so you can command constantly.
    self.say("I need coins!")
    self.moveXY(x, y)
    # If you have funds for a soldier, summon one.
    if self.gold > self.costOf("soldier"):
        self.say("I should summon something here!")
        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 = soldiers[soldierIndex]

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

```

---

<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:** [December 18, 2015, 9:27pm UTC](https://discourse.codecombat.com/t/mounatin-mercenaries-error/6174/11 "2015-12-18T21:27:46Z")

</div>

You don’t define `target`. Do you mean “`enemy`”?

---

<div class="post-metadata">

**Author:** ![J\_Butch](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/j_butch/32/3483_2.png) [@J\_Butch](https://discourse.codecombat.com/u/J_Butch)\
**Post date:** [December 18, 2015, 11:31pm UTC](https://discourse.codecombat.com/t/mounatin-mercenaries-error/6174/12 "2015-12-18T23:31:10Z")

</div>

```python
# Gather coins to summon soldiers and have them attack the enemy
item = self.findNearestItem()
itemPos = item.pos
x = itemPos.x
y = itemPos.y

loop:
    # Move to the nearest coin.
    # Use move instead of moveXY so you can command constantly.
    self.say("I need coins!")
    self.moveXY(x, y)
    # If you have funds for a soldier, summon one.
    if self.gold > self.costOf("soldier"):
        self.say("I should summon something here!")
        self.summon("soldier")
    enemy = self.findNearestEnemy()
    if enemy:
        # Loop over all your soldiers and order them to attack.
        soldiers = self.findFriends()
        soldierIndex = 0
        soldier = soldiers[soldierIndex]

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

```

![](https://cdck-file-uploads-us1.s3.dualstack.us-west-2.amazonaws.com/flex016/uploads/codecombat/original/2X/a/a8b58f3d2354c659cead087e26501e86f9681db9.PNG)  
 ![](https://cdck-file-uploads-us1.s3.dualstack.us-west-2.amazonaws.com/flex016/uploads/codecombat/original/2X/9/9b916410cb6c524486be1598691e340190f46ed0.PNG)

---

<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:** [December 19, 2015, 12:21am UTC](https://discourse.codecombat.com/t/mounatin-mercenaries-error/6174/13 "2015-12-19T00:21:09Z")

</div>

I see a few problems. You define `item` once, but not again, so your hero will only pick up the nearest coin once. Also, you command only the first soldier to do anything.

---

<div class="post-metadata">

**Author:** ![J\_Butch](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/j_butch/32/3483_2.png) [@J\_Butch](https://discourse.codecombat.com/u/J_Butch)\
**Post date:** [January 6, 2016, 8:41pm UTC](https://discourse.codecombat.com/t/mounatin-mercenaries-error/6174/14 "2016-01-06T20:41:01Z")

</div>

This is the line that has an error:

```python
soldiers = self.findFriends()

```

---

<div class="post-metadata">

**Author:** ![J\_Butch](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/j_butch/32/3483_2.png) [@J\_Butch](https://discourse.codecombat.com/u/J_Butch)\
**Post date:** [January 13, 2016, 12:01am UTC](https://discourse.codecombat.com/t/mounatin-mercenaries-error/6174/15 "2016-01-13T00:01:02Z")

</div>

I think its just that I have crap gear. I bought a short sword and made the code so I just attacked, but I still die. You should just give me like 2600 gems and I will be good

---

<div class="post-metadata">

**Author:** ![ChronistGilver](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chronistgilver/32/3778_2.png) [@ChronistGilver](https://discourse.codecombat.com/u/ChronistGilver)\
**Post date:** [January 13, 2016, 3:49am UTC](https://discourse.codecombat.com/t/mounatin-mercenaries-error/6174/16 "2016-01-13T03:49:37Z")

</div>

## It’s basically out of the question to give you gems. We want you to progress on your own. Hitting us up for gems isn’t the best way to do this. You could always try simulating. Go here: [http://codecombat.com/play/ladder/cavern-survival#simulate](http://codecombat.com/play/ladder/cavern-survival#simulate) and hit the button that says “simulate”. You will get gems based upon how many you have done.

Out of curiosity, why are you wearing Wooden Glasses? You should have at least the Mahogany Glasses by now…

---

<div class="post-metadata">

**Author:** ![J\_Butch](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/j_butch/32/3483_2.png) [@J\_Butch](https://discourse.codecombat.com/u/J_Butch)\
**Post date:** [January 13, 2016, 7:04pm UTC](https://discourse.codecombat.com/t/mounatin-mercenaries-error/6174/17 "2016-01-13T19:04:03Z")

</div>

I prefer the wooden glasses so I can use nearest enemy/nearest item. But now that I know how to use the nearest and enemies code, I will be using the twilight glasses

---

<div class="post-metadata">

**Author:** ![J\_Butch](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/j_butch/32/3483_2.png) [@J\_Butch](https://discourse.codecombat.com/u/J_Butch)\
**Post date:** [January 13, 2016, 7:15pm UTC](https://discourse.codecombat.com/t/mounatin-mercenaries-error/6174/18 "2016-01-13T19:15:43Z")

</div>

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

loop:
    items = self.findItems()
    item = self.findNearest(items)
    itemPos = item.pos
    x = itemPos.x
    y = itemPos.y
    # Move to the nearest coin.
    # Use move instead of moveXY so you can command constantly.
    self.moveXY(x, y)
    # If you have funds for a soldier, summon one.
    if self.gold > self.costOf("soldier"):
        self.summon("soldier")
    enemies = self.findEnemies()
    enemy = self.findNearest(enemies)
    if enemy:
        # Loop over all your soldiers and order them to attack.
        soldiers = self.findFriends()
        soldierIndex = 0
        soldier = soldiers[soldierIndex]

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

```

Now the problem is `self.command(soldier, "attack", enemy)`  
It says: ‘Hero Placeholder needs something to command’

---

<div class="post-metadata">

**Author:** ![AdrianCgw](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@AdrianCgw](https://discourse.codecombat.com/u/AdrianCgw)\
**Post date:** [January 14, 2016, 3:29am UTC](https://discourse.codecombat.com/t/mounatin-mercenaries-error/6174/19 "2016-01-14T03:29:22Z")

</div>

soldiers is a indexed list.  
It will contain the several values: soldiers[0], soldiers[1], soldiers[2], …  
The length of the list is given by _len(soldiers)_  
Since the index numbers start from 0, the last index will be _len(soliders)-1_

Example:

```python
mylist = [5,6,7]
# the length of this list is len(mylist) = 3
# the elements are mylist[0] = 5, mylist[1] =6, mylist[2] =7

```

Now knowing all this you can write:

```python
soldierIndex=0
while (soldierIndex < len(soldiers)):
    # do something with soldiers[soldierIndex]
    soldierIndex++

```

A faster way to write the same loop:

```python
for i in range(len(soldiers)):
    # do something with soldiers[i]

```

The **for** structure automatically makes i go from 0 to len(soldiers)-1

Even faster

```python
for soldier in soldiers:
    #do something with solider

```

Instead of complicating with the index, this **for** makes solider go from soliders[0] to soldiers[len(soldiers)-1]

---

<div class="post-metadata">

**Author:** ![J\_Butch](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/j_butch/32/3483_2.png) [@J\_Butch](https://discourse.codecombat.com/u/J_Butch)\
**Post date:** [January 14, 2016, 7:09pm UTC](https://discourse.codecombat.com/t/mounatin-mercenaries-error/6174/20 "2016-01-14T19:09:08Z")

</div>

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

loop:
    items = self.findItems()
    item = self.findNearest(items)
    itemPos = item.pos
    x = itemPos.x
    y = itemPos.y
    # Move to the nearest coin.
    # Use move instead of moveXY so you can command constantly.
    self.moveXY(x, y)
    # If you have funds for a soldier, summon one.
    if self.gold > self.costOf("soldier"):
        self.summon("soldier")
    enemies = self.findEnemies()
    enemy = self.findNearest(enemies)
    if enemy:
        # Loop over all your soldiers and order them to attack.
        soldiers = self.findFriends()
        soldierIndex = 0
        soldier = soldiers[soldierIndex]

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

```

OK This is my code. Everything works but my soldiers don’t attack

---

<div class="post-metadata">

**Author:** ![AdrianCgw](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@AdrianCgw](https://discourse.codecombat.com/u/AdrianCgw)\
**Post date:** [January 15, 2016, 3:21am UTC](https://discourse.codecombat.com/t/mounatin-mercenaries-error/6174/21 "2016-01-15T03:21:53Z")

</div>

The code hint says:

```python
# Loop over all your soldiers and order them to attack.

```

Look at my post above. No spoonfeeding

---

<div class="post-metadata">

**Author:** ![J\_Butch](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/j_butch/32/3483_2.png) [@J\_Butch](https://discourse.codecombat.com/u/J_Butch)\
**Post date:** [January 19, 2016, 9:53pm UTC](https://discourse.codecombat.com/t/mounatin-mercenaries-error/6174/22 "2016-01-19T21:53:15Z")

</div>

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

loop:
    items = self.findItems()
    item = self.findNearest(items)
    itemPos = item.pos
    x = itemPos.x
    y = itemPos.y
    # Move to the nearest coin.
    # Use move instead of moveXY so you can command constantly.
    self.moveXY(x, y)
    # If you have funds for a soldier, summon one.
    if self.gold > self.costOf("soldier"):
        self.summon("soldier")
    enemies = self.findEnemies()
    enemy = self.findNearest(enemies)
    if enemy:
        # Loop over all your soldiers and order them to attack.
        soldiers = self.findFriends()
        soldierIndex += 1
        soldier = soldiers[soldierIndex]
        soldierIndex += 1
        myList = [5, 6, 7]
        # Use the 'attack' command to make your soldiers attack.
        #self.command(soldier, "attack", enemy)
for soldier in soldiers: 
    self.command(soldier, "attack", enemy)

```

Is this right? Because it still doesn’t work

[Next page](https://discourse.codecombat.com/t/mounatin-mercenaries-error/6174.md?page=2)
