# Mountain Mecernaries Assistance

**URL:** <https://discourse.codecombat.com/t/mountain-mecernaries-assistance/31495>\
**Category:** Level Help\
**Created:** [December 3, 2021, 10:02am UTC](https://discourse.codecombat.com/t/mountain-mecernaries-assistance/31495 "2021-12-03T10:02:07Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![RiceRunner](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ricerunner/32/38852_2.png) [@RiceRunner](https://discourse.codecombat.com/u/RiceRunner)\
**Post date:** [December 3, 2021, 10:02am UTC](https://discourse.codecombat.com/t/mountain-mecernaries-assistance/31495/1 "2021-12-03T10:02:07Z")

</div>

```python
# Gather coins to summon soldiers and have them attack the enemy.
while True:
    hero.findNearestItem()
    coin = NearestItem
    # Move to the nearest coin.
    # Use move instead of moveXY so you can command constantly.
    if coin:
        hero.move(coin.pos.x) (coin.pos.y)    
        hero.say("I need coins!")
    # 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:
        soldiers = hero.findFriends()
        soldierIndex = 0
        soldier = soldiers[soldierIndex]
        # Loop over all your soldiers and order them to attack.
        while True:
            # Use the 'attack' command to make your soldiers attack
            hero.command(soldier, "attack", enemy)
            #hero.command(soldier, "attack", enemy)

```

So using this Python code gives me  
 ![image](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/5/8/585549028e74a644ad9204347028cf42e4caa0bd.png)  
but if I remove line 4 it gives me  
 ![image](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/0/5/05a7971b84aba8a52953b1d38baa30f8e27e516e.png)  
and i’m really confused on what to do to fix it.

---

<div class="post-metadata">

**Author:** ![Aya](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/aya/32/42680_2.png) [@Aya](https://discourse.codecombat.com/u/Aya)\
**Post date:** [December 3, 2021, 12:29pm UTC](https://discourse.codecombat.com/t/mountain-mecernaries-assistance/31495/2 "2021-12-03T12:29:47Z")

</div>

> [@RiceRunner](#):
>
> ```python
> hero.findNearestItem()
> coin = NearestItem
> 
> ```

This should be one statement

---

<div class="post-metadata">

**Author:** ![Aya](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/aya/32/42680_2.png) [@Aya](https://discourse.codecombat.com/u/Aya)\
**Post date:** [December 4, 2021, 5:13pm UTC](https://discourse.codecombat.com/t/mountain-mecernaries-assistance/31495/3 "2021-12-04T17:13:01Z")

</div>

Was the problem solved @RiceRunner ?

---

<div class="post-metadata">

**Author:** ![RiceRunner](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ricerunner/32/38852_2.png) [@RiceRunner](https://discourse.codecombat.com/u/RiceRunner)\
**Post date:** [December 4, 2021, 5:18pm UTC](https://discourse.codecombat.com/t/mountain-mecernaries-assistance/31495/4 "2021-12-04T17:18:24Z")

</div>

Sorry I’ve been busy ill try it later

---

<div class="post-metadata">

**Author:** ![RiceRunner](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ricerunner/32/38852_2.png) [@RiceRunner](https://discourse.codecombat.com/u/RiceRunner)\
**Post date:** [December 7, 2021, 9:29am UTC](https://discourse.codecombat.com/t/mountain-mecernaries-assistance/31495/5 "2021-12-07T09:29:09Z")

</div>

> [@RiceRunner](#):
>
> `hero.findNearestItem() coin = NearestItem`

Like this?  
Sorry i’ve been busy with school and homework recently

---

<div class="post-metadata">

**Author:** ![Aya](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/aya/32/42680_2.png) [@Aya](https://discourse.codecombat.com/u/Aya)\
**Post date:** [December 7, 2021, 10:07am UTC](https://discourse.codecombat.com/t/mountain-mecernaries-assistance/31495/6 "2021-12-07T10:07:31Z")

</div>

No, make this first statement a variable, `variable = hero.something`

> **Hint (think about it first)**
>
> Try another time before this! → `coin = hero.findNearestItem()`

---

<div class="post-metadata">

**Author:** ![RiceRunner](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ricerunner/32/38852_2.png) [@RiceRunner](https://discourse.codecombat.com/u/RiceRunner)\
**Post date:** [December 7, 2021, 10:15am UTC](https://discourse.codecombat.com/t/mountain-mecernaries-assistance/31495/7 "2021-12-07T10:15:42Z")

</div>

Would it be  
` coin = hero.findNearestItem?`  
I’d put that at the start right?  
I haven’t checked the hint yet incase i’m wrong

---

<div class="post-metadata">

**Author:** ![Aya](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/aya/32/42680_2.png) [@Aya](https://discourse.codecombat.com/u/Aya)\
**Post date:** [December 7, 2021, 10:19am UTC](https://discourse.codecombat.com/t/mountain-mecernaries-assistance/31495/8 "2021-12-07T10:19:16Z")

</div>

That’s right, but don’t forget the parenthesis, and yes at the top, though inside the `while True` loop

---

<div class="post-metadata">

**Author:** ![RiceRunner](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ricerunner/32/38852_2.png) [@RiceRunner](https://discourse.codecombat.com/u/RiceRunner)\
**Post date:** [December 10, 2021, 11:08am UTC](https://discourse.codecombat.com/t/mountain-mecernaries-assistance/31495/9 "2021-12-10T11:08:56Z")

</div>

```python
while True:
    coin = hero.findNearestItem()
    # Move to the nearest coin.
    # Use move instead of moveXY so you can command constantly.
    if coin:
        hero.move(coin.pos.x) (coin.pos.y)

```

Apparantly there’s something wrong on the last line

---

<div class="post-metadata">

**Author:** ![Aya](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/aya/32/42680_2.png) [@Aya](https://discourse.codecombat.com/u/Aya)\
**Post date:** [December 10, 2021, 12:04pm UTC](https://discourse.codecombat.com/t/mountain-mecernaries-assistance/31495/10 "2021-12-10T12:04:19Z")

</div>

This statement takes only one parameter, and i doubt that there is any method that takes more than one pair of parenthesis.  
You can either do: `hero.move(coin.pos)`  
or `hero.moveXY(coin.posx, coin.pos.y)`

---

<div class="post-metadata">

**Author:** ![RiceRunner](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ricerunner/32/38852_2.png) [@RiceRunner](https://discourse.codecombat.com/u/RiceRunner)\
**Post date:** [December 10, 2021, 12:04pm UTC](https://discourse.codecombat.com/t/mountain-mecernaries-assistance/31495/11 "2021-12-10T12:04:50Z")

</div>

Cool, i’ve got an english assessment rn, so ill try it later
