The problem with your code, as you’ve probably found out, is the commanding.
Here, you’re using a for loop to single out a single soldier to command.
In the command Paladin function you’re doing the right thing: commanding a single paladin.
But in the archer and soldier you’re making another for loop, why? Why not command the single friend that you very cleverly made in the commandFriends function (‘archer’ and ‘soldier’.)
You can take this code and use it just for archer, you don’t need to loop through all your friends again, because you did that in the commandFriends function:
This section, and the section from your soldier commanding code, out of the for loop. Should stay where they are, but you need to get rid of the for loop and command the ‘archer’ and the ‘soldier’ rather than ‘friend’ from your for-loop.
This section is what I’m talking about.
When you’re commanding troops, you can use a for loop straight away:
for friend in friends:
hero.command(friend, 'dosomething', someone)
OR:
def doSomething(friend):
hero.command(friend, 'dosomething', someone)
for friend in friends:
doSomething(friend)
As you can see, in the second example you make a function to command ONE friend. Then you use a for loop and call the function for each INDIVIDUAL troop (sorry for the caps, I want to accent those words because they’re very important)
Your trying to mix these tactics.
The functions commandArcher and commandSoldiers should be commanding INDIVIDUAL soldiers and archers, then you can call them for each troop in the for loop in your commandTroops function.
Imagine commandArcher was a single command like hero.command(archer, ‘attack’, enemy), you’re only commanding one soldier to do something. You don’t need another for loop inside your commandArcher function you can use just something like:
enemy = hero.findNearestEnemy()
if enemy and someCondition == True:
hero.command(archer, 'doSomething', enemy)
Is it working? I feel like at this point it’s kind of to do with your tactics because that code doesn’t seem to have any errors.
Danny
P.S. you may want to use flags.