[Solved] How do you command properly

I can’t seem to figure out how to command my troops to attack this is my code:def commandSoldiers():
enemies = hero.findEnemies()
enemy = hero.findNearest(enemies)
soldiers = hero.findFriends()
soldier = soldiers[0]
for soldier in soldiers:

    hero.command(soldier, "attack", enemy)

It always does this

it is because a peasant is the nearest friend try using findByType(minnion name)

1 Like

So I have to find the soldier I get it

I actually like using for-loops better than all those indexes.
For-loops are nice and simple,
You just have to define friends and then you can command by using a for-loop!

while True:
     friends = hero.findFriends()
     for friend in friends: 
          #command your friends

It is nice and simple!

1 Like

okay still getting cozy with for-loops but I like while loops

1 Like

You could also just add an if loop identifying all soldiers.

if soldier.type == "soldier":

That way, all friends that are soldier types follow that command.

1 Like

I got it @abc this is really helping me out command my pesky soldiers

I agree with @riticmaster9087 on this one. The findByType() method works very well if you have the correct glasses that include this method. One note for this method, you need to understand that this is going to return an array list of all the soldiers. So using a for loop to command them individually works very well.

You can also include an additional parameter that ensures you are only finding friendly soldiers or whatever type you search for. This is important when you fight against warlocks since they can raise your soldiers from the dead to fight against you. If you don’t include the friends limitation, you will try to command the raised soldiers that are now enemies and you can’t, you will get an error.

hero.findByType("soldier", hero.findFriends())

Otherwise, using a for loop with your friends like @Lydia_Song suggested with the type check included like @abc mentioned is another great way to isolate the type of friends you want to command.

Extra note for those that are new to commanding friends: you have the right Boss Star that allows you command the different friends.

thanks @brooksy125, @Lydia_Song, @abc, and @riticmaster9087 you guys have been a big help now I can tell my troops to serve me fried munchkins

1 Like

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