Cloudrip Commander help plz

Hi, everyone!
Just started the new :mountain: world
Kinda stuck on this level and I don’t understand how… :thinking:
Any help at all would be very much appreciated! :smile:
Here’s my PYTHON code:

# 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})
while True:
    hero.moveXY(51, 41)

What’s wrong with this?

The problem is that you are using a while True loop. It is important to know that while True loops are actually infinite loops which don’t end unless you use break, that is why they are not as common in real coding as they are in CoCo.
Instead you must use the kind of while loops you learned to use in the desert levels e.g.

while someCounter < someNumber:
    #execute code

At the moment your code won’t have reached the moveXY command, but when you have fixed your code, why don’t you take it out of the loop? It will work with it in there, but it’s unnecessary, as moveXY (unlike move() which you may not have come across :thinking:) doesn’t need any type of loop. It takes you there by itself.
I hope this helps,
Danny

2 Likes

I have come across move()

I still don’t understand what to put after while in

while: #what do i put here?

I know it seems like im asking for an answer but I am not advanced enough to know what else to say… :expressionless:

It’s alright, if you’re stuck go back to earlier sarven levels. I recommend “sarven saviour”, “bank raid”, “lurkers” and , if you’re a subscriber, all the mad-maxer levels.
It’s really about how to iterate over a while loop. Remember you need an index and you need to increment it. (index += 1) And then check that it’s less than a certain no. of somethings…

1 Like

Thanks for dumbing it down for me :smile:
I understand now :laughing:

1 Like