# Help - Cloudrip Commander

**URL:** <https://discourse.codecombat.com/t/help-cloudrip-commander/32113>\
**Category:** Level Help\
**Created:** [February 16, 2022, 1:42pm UTC](https://discourse.codecombat.com/t/help-cloudrip-commander/32113 "2022-02-16T13:42:15Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![pugster](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/pugster/32/27576_2.png) [@pugster](https://discourse.codecombat.com/u/pugster)\
**Post date:** [February 16, 2022, 1:42pm UTC](https://discourse.codecombat.com/t/help-cloudrip-commander/32113/1 "2022-02-16T13:42:15Z")

</div>

```python
# Summon some soldiers, then direct them to your base.

# Each soldier costs 20 gold.
"while hero.gold > hero.costOf("soldier"):
    hero.summon("soldier")
    
soldiers = hero.findFriends()
soldierIndex = 0
# Add a while loop to command all the soldiers.
friends = hero.findFriends()
while soldierIndex < len(friends):
    hero.findFriends()
    if friends:
        hero.command(soldier, "move", {"x": 50, "y": 40})
hero.moveXY(50, 40)"

```

it wont let me move, it says:

 ![image](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/5/a/5adc32c8c1d7db99e049497f22cc91b2477e094a.jpeg)

---

<div class="post-metadata">

**Author:** ![MarcusL123](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/marcusl123/32/23238_2.png) [@MarcusL123](https://discourse.codecombat.com/u/MarcusL123)\
**Post date:** [February 16, 2022, 2:14pm UTC](https://discourse.codecombat.com/t/help-cloudrip-commander/32113/2 "2022-02-16T14:14:24Z")

</div>

Hello! can you please format your code by pressing the \</\> button?

Thanks!

---

<div class="post-metadata">

**Author:** ![qwerty](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/qwerty/32/30493_2.png) [@qwerty](https://discourse.codecombat.com/u/qwerty)\
**Post date:** [February 16, 2022, 2:34pm UTC](https://discourse.codecombat.com/t/help-cloudrip-commander/32113/3 "2022-02-16T14:34:31Z")

</div>

Formated a bit better:

```python
# Summon some soldiers, then direct them to your base.

# Each soldier costs 20 gold.
while hero.gold > hero.costOf("soldier"):
    hero.summon("soldier")
    
soldiers = hero.findFriends()
soldierIndex = 0
# Add a while loop to command all the soldiers.
friends = hero.findFriends()
while soldierIndex < len(friends):
    hero.findFriends()
    if friends:
        hero.command(soldier, "move", {"x": 50, "y": 40})
hero.moveXY(50, 40)

```

---

<div class="post-metadata">

**Author:** ![qwerty](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/qwerty/32/30493_2.png) [@qwerty](https://discourse.codecombat.com/u/qwerty)\
**Post date:** [February 16, 2022, 2:36pm UTC](https://discourse.codecombat.com/t/help-cloudrip-commander/32113/4 "2022-02-16T14:36:05Z")

</div>

> [@qwerty](#):
>
> ```python
> while soldierIndex < len(friends):
> hero.findFriends()
> if friends:
> 
> ```

I changed this whole section to `for soldier in soldiers:` and moved this

> [@qwerty](#):
>
> `soldiers = hero.findFriends()`

into the summoning bit and it worked

---

<div class="post-metadata">

**Author:** ![pugster](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/pugster/32/27576_2.png) [@pugster](https://discourse.codecombat.com/u/pugster)\
**Post date:** [February 16, 2022, 4:41pm UTC](https://discourse.codecombat.com/t/help-cloudrip-commander/32113/5 "2022-02-16T16:41:23Z")

</div>

now it is only moving soldier to the X

---

<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:** [February 16, 2022, 5:07pm UTC](https://discourse.codecombat.com/t/help-cloudrip-commander/32113/6 "2022-02-16T17:07:18Z")

</div>

Can you please post your new code?

---

<div class="post-metadata">

**Author:** ![CryptiCrystal](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/crypticrystal/32/16228_2.png) [@CryptiCrystal](https://discourse.codecombat.com/u/CryptiCrystal)\
**Post date:** [February 16, 2022, 9:13pm UTC](https://discourse.codecombat.com/t/help-cloudrip-commander/32113/7 "2022-02-16T21:13:05Z")

</div>

or instead replace `soldier` with `soldiers[soldierIndex]` and then add a `soldierIndex += 1` in the while loop

---

<div class="post-metadata">

**Author:** ![MarcusL123](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/marcusl123/32/23238_2.png) [@MarcusL123](https://discourse.codecombat.com/u/MarcusL123)\
**Post date:** [February 17, 2022, 3:10am UTC](https://discourse.codecombat.com/t/help-cloudrip-commander/32113/8 "2022-02-17T03:10:58Z")

</div>

You’d probably have to use

```python
for soldier in soldiers
hero.command(soldier, "move" {"x": number, "y": number})
hero.moveXY(blah, blah)

```

this makes it easier

---

<div class="post-metadata">

**Author:** ![herokolbert](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/herokolbert/32/34618_2.png) [@herokolbert](https://discourse.codecombat.com/u/herokolbert)\
**Post date:** [February 20, 2022, 11:40pm UTC](https://discourse.codecombat.com/t/help-cloudrip-commander/32113/9 "2022-02-20T23:40:30Z")

</div>

but indent the 2nd and third lines

---

<div class="post-metadata">

**Author:** ![pugster](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/pugster/32/27576_2.png) [@pugster](https://discourse.codecombat.com/u/pugster)\
**Post date:** [February 23, 2022, 2:23pm UTC](https://discourse.codecombat.com/t/help-cloudrip-commander/32113/10 "2022-02-23T14:23:50Z")

</div>

still not working!!!

---

<div class="post-metadata">

**Author:** ![Endsoldier](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/endsoldier/32/27729_2.png) [@Endsoldier](https://discourse.codecombat.com/u/Endsoldier)\
**Post date:** [February 23, 2022, 2:52pm UTC](https://discourse.codecombat.com/t/help-cloudrip-commander/32113/11 "2022-02-23T14:52:57Z")

</div>

Return to your old code and face the error. It says soldier is not defined. So use a variable for your fsoldier that is defined.

---

<div class="post-metadata">

**Author:** ![herokolbert](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/herokolbert/32/34618_2.png) [@herokolbert](https://discourse.codecombat.com/u/herokolbert)\
**Post date:** [March 8, 2022, 10:59pm UTC](https://discourse.codecombat.com/t/help-cloudrip-commander/32113/12 "2022-03-08T22:59:29Z")

</div>

wait for the for-loop make sure you have a colen at the end, because normally when you do that kind of for-loop it makes the var for you.
