# Stuck on mounten mernchnts

**URL:** <https://discourse.codecombat.com/t/stuck-on-mounten-mernchnts/10609>\
**Category:** Uncategorized\
**Created:** [February 18, 2017, 3:27pm UTC](https://discourse.codecombat.com/t/stuck-on-mounten-mernchnts/10609 "2017-02-18T15:27:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ajdv](https://avatars.discourse-cdn.com/v4/letter/a/f04885/32.png) [@ajdv](https://discourse.codecombat.com/u/ajdv)\
**Post date:** [February 18, 2017, 3:27pm UTC](https://discourse.codecombat.com/t/stuck-on-mounten-mernchnts/10609/1 "2017-02-18T15:27:25Z")

</div>

my code isnt working

```python
while True:
    # Move to the nearest coin.
    # Use move instead of moveXY so you can command constantly.
    items = hero.findItems()
    itemIndex = 0
    hero.say("I need coins!")
    item = items[itemIndex]
    hero.move(itemPos)
    # 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
        soldier = soldiers[soldierIndex]
        
        # Use the 'attack' command to make your soldiers attack.
        #hero.command(soldier, "attack", enemy)
        hero.command(soldier, "attack", target)

```

line 10 is the one that it sase has an error

---

<div class="post-metadata">

**Author:** ![Hellenar](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/hellenar/32/9100_2.png) [@Hellenar](https://discourse.codecombat.com/u/Hellenar)\
**Post date:** [February 19, 2017, 4:28am UTC](https://discourse.codecombat.com/t/stuck-on-mounten-mernchnts/10609/2 "2017-02-19T04:28:15Z")

</div>

I see what’s going on. The hero is not considering whether or not an item exists, so the statement

```python
hero.move(item.pos)

```

returns a null value.  
Try including:

```python
if item:

```

And your first ten or so lines of code will work.

I also do not see any looping over soldierIndex. Try placing a for-loop before defining

```python
soldier = soldiers[soldierIndex]

```

and also incrementing soldierIndex after you command your soldiers.  
Then your code will be able to run with no errors, and you’ll beat the level.

Happy to help! 😃

---

<div class="post-metadata">

**Author:** ![ajdv](https://avatars.discourse-cdn.com/v4/letter/a/f04885/32.png) [@ajdv](https://discourse.codecombat.com/u/ajdv)\
**Post date:** [March 1, 2017, 2:54pm UTC](https://discourse.codecombat.com/t/stuck-on-mounten-mernchnts/10609/3 "2017-03-01T14:54:31Z")

</div>

it still isnt working it sase that line 12 move’s argument pos should have been type object but got null target an {x:number, y:number} position

---

<div class="post-metadata">

**Author:** ![ajdv](https://avatars.discourse-cdn.com/v4/letter/a/f04885/32.png) [@ajdv](https://discourse.codecombat.com/u/ajdv)\
**Post date:** [March 1, 2017, 2:57pm UTC](https://discourse.codecombat.com/t/stuck-on-mounten-mernchnts/10609/4 "2017-03-01T14:57:49Z")

</div>

this is my new code

```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.
    items = hero.findItems()
    itemIndex = 0
    hero.say("I need coins!")
    item = items[itemIndex]
    if item < hero.costOf("soldier"):
        
        hero.move(item.Pos)
        item +=1
    # 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())
    soldier = soldiers[soldierIndex]
    if enemy:
        # Loop over all your soldiers and order them to attack.
        
        soldiers = hero.findFriends()
        soldierIndex = 0
        
        
        # Use the 'attack' command to make your soldiers attack.
        #hero.command(soldier, "attack", enemy)
        hero.command(soldier, "attack", target)
        soldierIndex += 1

```

---

<div class="post-metadata">

**Author:** ![Luke10](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/luke10/32/19892_2.png) [@Luke10](https://discourse.codecombat.com/u/Luke10)\
**Post date:** [March 1, 2017, 7:52pm UTC](https://discourse.codecombat.com/t/stuck-on-mounten-mernchnts/10609/5 "2017-03-01T19:52:33Z")

</div>

> [@ajdv](#):
>
> soldierIndex +=

> [@ajdv](#):
>
> +=1

Were those supposed to be there? You think you could send a screenshot and what is it saying error wise?

---

<div class="post-metadata">

**Author:** ![ajdv](https://avatars.discourse-cdn.com/v4/letter/a/f04885/32.png) [@ajdv](https://discourse.codecombat.com/u/ajdv)\
**Post date:** [March 14, 2017, 4:55pm UTC](https://discourse.codecombat.com/t/stuck-on-mounten-mernchnts/10609/6 "2017-03-14T16:55:30Z")

</div>

it sase i need to loop over my soldiers but i can’t remember how

---

<div class="post-metadata">

**Author:** ![ajdv](https://avatars.discourse-cdn.com/v4/letter/a/f04885/32.png) [@ajdv](https://discourse.codecombat.com/u/ajdv)\
**Post date:** [March 14, 2017, 5:33pm UTC](https://discourse.codecombat.com/t/stuck-on-mounten-mernchnts/10609/7 "2017-03-14T17:33:20Z")

</div>

never mind i got it! thanks thoe
