sigh I just told you to format your code properly. How to people still manage to use block quotes?
What ant told you to do is to replace friends.length with len(friends). However, it appears that you took away more than what was intended. Your code in post 16 is good with that change.
enemy = self.findNearest(self.findEnemies())
i = 0
friends = self.findFriends()
while i < len(friends):
friend = friends[i]
self.command(friend, "attack",enemy)
i = i + 1
That’s because you command them to attack your nearest enemy. Therefore, they all go to one place, trying to attack, then the catapults launch and all of them die. Better to tell them to attack their nearest enemy. That would work better.
Once again, we do not post “right code”, as you call it.
Go back to other levels if you need help remembering how to command your units (Mountain Mercenaries, Timber Guard, Vital Powers, and Hunters and Prey come to mind)
enemy = friends.findNearest(self.findEnemies())
i = 0
friends = self.findFriends()
while i < len(friends):
friend = friends[i]
self.command(friend, "attack", enemy)
i = i + 1