# \[SOLVED\] Stuck cloudrip commander

**URL:** <https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439>\
**Category:** Adventurer\
**Created:** [April 8, 2015, 6:17am UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439 "2015-04-08T06:17:46Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![Hanoo](https://avatars.discourse-cdn.com/v4/letter/h/7ab992/32.png) [@Hanoo](https://discourse.codecombat.com/u/Hanoo)\
**Post date:** [November 25, 2015, 10:45pm UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439/26 "2015-11-25T22:45:34Z")

</div>

```python
#Help! my code is not working

while self.gold > self.costOf("soldier"):
    self.summon("soldier")
hi = 0    
while hi < 6:
    soldiers = self.findFriends()
    soldierIndex = 0
    soldier = soldiers[soldierIndex]
    self.command(soldier, "move", {"x": 50, "y": 40})
    hi += 1
    self.moveXY(50, 40)
    solderIndex += 1

```

---

<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:** [November 26, 2015, 4:38am UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439/27 "2015-11-26T04:38:56Z")

</div>

Hello, Hanoo, and welcome. Please read the FAQ before you post again. It is essential that you learn how to format your code properly. I have done it for you this time, but please do it yourself in the future.

We need more information than “This code doesn’t work!” or any such variants. Give us a detailed description of you error.

---

<div class="post-metadata">

**Author:** ![ant](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ant/32/3362_2.png) [@ant](https://discourse.codecombat.com/u/ant)\
**Post date:** [November 26, 2015, 9:46am UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439/28 "2015-11-26T09:46:34Z")

</div>

Your basic idea is OK, but you reset the index every time the loop runs with the `soldierIndex = 0` line. Move that outside the loop and it should be OK.

* * *

Further points to improve:

- you can use `soldierIndex` for the `while` loop condition
- so you don’t really need the `hi` variable
- you can safely move the `soldiers = self.findFriends()` line out of the loop
- you don’t need to move to the destination every time the loop only when you finished sending your friends there – move that out of the loop too (_hint:_ unindent)

Cheers

---

<div class="post-metadata">

**Author:** ![charlieduff81](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/charlieduff81/32/4035_2.png) [@charlieduff81](https://discourse.codecombat.com/u/charlieduff81)\
**Post date:** [December 16, 2015, 3:44pm UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439/30 "2015-12-16T15:44:43Z")

</div>

This level might need to be fixed so people can’t use simple commands like this

```
self.moveXY(50, 42)
loop:
    self.summon("soldier")
```

---

<div class="post-metadata">

**Author:** ![junglywood](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/junglywood/32/3643_2.png) [@junglywood](https://discourse.codecombat.com/u/junglywood)\
**Post date:** [January 21, 2016, 2:22am UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439/31 "2016-01-21T02:22:46Z")

</div>

Help! I,m stuck on Cloudrip Commander.

---

<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 21, 2016, 4:23am UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439/32 "2016-01-21T04:23:20Z")

</div>

Jungly, we can’t help you unless you talk about a specific case  
Example:

1. I don’t know how to do **this\_simple\_step**
2. I am trying to do **this\_simple\_step** but instead I get **this\_error** on **this\_line**.
3. I am trying to do **this\_devious\_plan** but when the code runs **this\_totally\_dispointing\_thing** happens  
I am attacking my code formated by surrounding with 3 backslashes ``` (top-left symbol on the keyboard)

```python

```

My code here

```python

```

---

<div class="post-metadata">

**Author:** ![Awsomedude1](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@Awsomedude1](https://discourse.codecombat.com/u/Awsomedude1)\
**Post date:** [February 27, 2016, 8:35pm UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439/33 "2016-02-27T20:35:13Z")

</div>

Help! I need help on cloudrip commander!

My code:

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

# Each soldier costs 20 gold.
while self.gold > self.costOf("soldier"):
    self.summon("soldier")
    
soldiers = self.findFriends()
soldierIndex = 0
soldier = soldiers[soldierIndex]
# Add a while loop to command all the soldiers.
while soldierIndex soldier:
    soldier = soldiers[soldierIndex]
    self.command(soldier, "move", {"x": 50, "y": 40})

# Go join your comrades!

```

---

<div class="post-metadata">

**Author:** ![UltCombo](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ultcombo/32/3822_2.png) [@UltCombo](https://discourse.codecombat.com/u/UltCombo)\
**Post date:** [February 27, 2016, 10:20pm UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439/34 "2016-02-27T22:20:41Z")

</div>

Please [format your code correctly](https://discourse.codecombat.com/faq#code-help). I’ve formatted it for you this time.

Your `while` loop has quite a few problems.

- The condition `while soldierIndex soldier` is wrong. It should be `soldierIndex < len(soldiers)`
- `soldier = soldiers[soldierIndex]` should be inside the loop
- You should increment the `soldierIndex` variable at the end of the loop.

Please review how you’ve done these loops in previous levels.  
Or just use a `for soldier in self.findFriends():`

---

<div class="post-metadata">

**Author:** ![Awsomedude1](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@Awsomedude1](https://discourse.codecombat.com/u/Awsomedude1)\
**Post date:** [February 29, 2016, 12:17am UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439/35 "2016-02-29T00:17:22Z")

</div>

thanks for the info.I will use it for other levels. By the way, I really do need help on the level treasure cave.  
Can you help?

My Code:

# That ogre died instantly! Better just avoid that yeti.

enemy = self.findEnemies()  
distance = self.distanceTo(enemy)  
item = self.findItems()

# We’ve hacked your fire-traps to go off after 5 seconds.

# The clearing to the north would be a good place for an explosive distraction.

# The yeti won’t stay distracted forever, so hurry and grab the coins!

loop:  
self.move({“x”: 73, “y”: 40})  
if self.distanceTo(enemy) \< 10:  
self.move({“x”: 72, “y”: 9})

---

<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:** [February 29, 2016, 12:58pm UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439/36 "2016-02-29T12:58:25Z")

</div>

Obviously you did not listen to UltCombo’s advice. Although yes, us moderators can format your code for you, we can’t be mother-henning you every hour of the day. Please read the FAQ, accessed by UltCombo’s link, so then we can help you.

---

<div class="post-metadata">

**Author:** ![Autri\_Basu](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@Autri\_Basu](https://discourse.codecombat.com/u/Autri_Basu)\
**Post date:** [February 6, 2017, 3:44pm UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439/37 "2017-02-06T15:44:59Z")

</div>

I have tried to rebeat this level, and have been having difficulties with the while loop.

```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.
while True:
    
    soldier = soldiers[soldierIndex]
    hero.command(soldier, "move", {"x": 50, "y": 40})

# Go join your comrades!
hero.move({"x": 50, "y": 40})

```

When I run the program, all it does is command one (of four summoned) soldiers and proceed to run out of time.  
Any advice?

---

<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:** [February 6, 2017, 4:49pm UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439/38 "2017-02-06T16:49:43Z")

</div>

The line:

`soldier = soldiers[soldierIndex]`

Then you command the soldier, but don’t actually increase the index. Remember back to the Desert levels about iterating over an array using a while loop.

---

<div class="post-metadata">

**Author:** ![17\_swords](https://avatars.discourse-cdn.com/v4/letter/1/e79b87/32.png) [@17\_swords](https://discourse.codecombat.com/u/17_swords)\
**Post date:** [April 18, 2017, 4:11pm UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439/39 "2017-04-18T16:11:41Z")

</div>

Help! My character just stops when all the soldiers reach the base!

# 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.

while soldiers:  
soldier = soldiers[soldierIndex]  
hero.command(soldier, “move”, {“x”: 50, “y”: 40})  
soldierIndex += 1

# Go join your comrades!

hero.moveXY(50, 40)

---

<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:** [April 19, 2017, 12:15am UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439/40 "2017-04-19T00:15:13Z")

</div>

Please format your code according to the FAQ using the triple backticks or this button:

```python
</>

```

🙂

---

<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:** [April 19, 2017, 12:16am UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439/41 "2017-04-19T00:16:02Z")

</div>

Use `while soldierIndex < len(soldiers):`  
Don’t use `while soldiers`

Also you should use `if hero.gold...` not `while hero.gold...` because when using the while loop the hero only does this while hero.gold is greater than or equal to the cost of a soldier and then breaks the loop.

---

<div class="post-metadata">

**Author:** ![Plebius](https://avatars.discourse-cdn.com/v4/letter/p/46a35a/32.png) [@Plebius](https://discourse.codecombat.com/u/Plebius)\
**Post date:** [April 27, 2017, 5:18am UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439/42 "2017-04-27T05:18:19Z")

</div>

Your while loop “while True” will always run and never stop so you’ll never get to the code after your while loop.

Also you’re not changing the value of soldierIndex so you’re commanding the same soldier each time.

soldiers is a list of soldiers soldiers[0], soldiers[1], soldiers[2]…soldiers[len(soldiers)-1]

So inside your while loop you want to change soldierIndex so that you’re commanding a different soldier each time through. Then you want your evaluation for the while loop to be something that lets the loop exit after all of the soldiers have been commanded instead of always being True forever. There are a couple of examples above you can piece together to figure this out.

---

<div class="post-metadata">

**Author:** ![fredandgeorge](https://avatars.discourse-cdn.com/v4/letter/f/a3d4f5/32.png) [@fredandgeorge](https://discourse.codecombat.com/u/fredandgeorge)\
**Post date:** [June 18, 2020, 3:51pm UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439/43 "2020-06-18T15:51:33Z")

</div>

I need help this is my code

```python
while hero.gold > hero.costOf("soldier"):
    hero.summon("soldier")
soldiers = hero.findFriends()
soldierIndex = 0
# Add a while loop to command all the soldiers.
soldier = soldiers[soldierIndex]
while soldierIndex < len(soldiers):
    hero.command(soldier, "move", {"x": 50, "y": 40})
    soldierIndex += 1
    pass

```

---

<div class="post-metadata">

**Author:** ![AnSeDra](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ansedra/32/13123_2.png) [@AnSeDra](https://discourse.codecombat.com/u/AnSeDra)\
**Post date:** [June 18, 2020, 4:18pm UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439/44 "2020-06-18T16:18:19Z")

</div>

> [@fredandgeorge](#):
>
> `soldier = soldiers[soldierIndex]`

This one put after

> [@fredandgeorge](#):
>
> `while soldierIndex < len(soldiers):`

So the soldier will keep updating. Also put 4 spaces before

> [@fredandgeorge](#):
>
> `soldier = soldiers[soldierIndex]`

Do you need any more assistance at this level?

---

<div class="post-metadata">

**Author:** ![fredandgeorge](https://avatars.discourse-cdn.com/v4/letter/f/a3d4f5/32.png) [@fredandgeorge](https://discourse.codecombat.com/u/fredandgeorge)\
**Post date:** [June 22, 2020, 2:56pm UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439/45 "2020-06-22T14:56:10Z")

</div>

no thanks for helping me.

---

<div class="post-metadata">

**Author:** ![AnSeDra](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ansedra/32/13123_2.png) [@AnSeDra](https://discourse.codecombat.com/u/AnSeDra)\
**Post date:** [June 22, 2020, 3:00pm UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439/46 "2020-06-22T15:00:10Z")

</div>

No problem! And congratulations for completing the level! 🥳

[Previous page](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439.md?page=1)

[Next page](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439.md?page=3)
