Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

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