I see a couple problems here:
You have not formatted your code properly. Please do that.
while (soldiers = self.findFriends): and the content inside the loop won’t work at all. You should move
soldierIndex outside of the loop and define soldiers beforehand. You also forgot to increment
soldierIndex after all the actions are taken.
In order to fix this, your code would look something like this:
#Summon some soldiers, then direct them to your base.
#Each soldier costs 20 gold.
while self.gold > self.costOf("soldier"):
soldiers = self.findFriends() #Define these OUTSIDE the while-loop
soldierIndex = 0
#Add a while loop to command all the soldiers.
while (soldierIndex < len(soldiers)):
#Do all your actions here
#Go join your comrades!