Summit's Gate error?

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.

So this code is right:

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

It would appear to be so, yes.

No this code is not working
what’s wrong with the code

Please provide more information. Phrases like “I need help!” and “This code doesn’t work!” don’t help us solve your problem.

this is what happens when I run the code.

<img src="//cdck-file-uploads-global.s3.dualstack.us-west-2.amazonaws.com/business6/uploads/codecombat/original/2X/a/a70ae82791cfbb1bb6c42117c903992a05152e52.png" width="349" height="243">

They line up to attack and then the catapults kill all of them

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.

How do I do that
please do the correction in my code and post the right code please

thanks

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)

can you tell me please

var friend = this.findNearest(this.findFriends);
var fEnemy = friend.findNearest(this.findEnemies);

Is this code right then

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