Help - Cloudrip Commander

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

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

Thanks!

Formated a bit better:

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

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

into the summoning bit and it worked

now it is only moving soldier to the X

Can you please post your new code?

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

You’d probably have to use

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

this makes it easier

but indent the 2nd and third lines

still not working!!!

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.

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.