[Solved]Cloudrip Commander(python)

Only one soldier follows me.

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

# Each soldier costs 20 gold.
while hero.gold > hero.costOf("soldier"):
    hero.summon("soldier")

while True:
    
    soldiers = hero.findFriends()
    soldierIndex = 0
    # Add a while loop to command all the soldiers.
    
    
    soldier = soldiers[soldierIndex]
    hero.command(soldier, "move", {"x": 51, "y": 41})
    
    # Go join your comrades!
    hero.moveXY(51, 41)

place this in the while loop
soldiers = hero.findFriends()
soldierIndex = 0
after that make a if soldier: loop after the soldier = soldiers[soldierIndex]
place the soldier move inside the if
then place a else then place a break in the else loop
lastly don’t put your hero moving inside any loop
Hope this helps

Replace while true with while soldierIndex < len(soldiers) and move it to after this line.

Lastly don’t forget the increment of soldierIndex at the end of while loop.

1 Like

this

and this ones numbers are different

How does that help the infinite loop of the hero doing nothing?

I changed it, it doesn’t help.

Delete this part it should solve the infinite loop problem, the part that is in the while soldier loop.

Why do you incriminent the soldierIndex only if there is a soldier. What happens when there is no soldier.

Andrei

@AnSeDra I didn’t know where to put it.

delete the other

in the

loop and you should be fine

Thanks, I can’t get to doing it today because we just started school today. But I will get back when I can.

1 Like

ok (2000000000000000000000)

Oh wait…I put the
soldiers = hero.findFriends() soldierIndex = 0
In the wrong spot. It works now, thanks!!! :smiling_face_with_three_hearts: :grin: :grin: :sweat_smile:

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.