[SOLVED] The bane of soldiers help please

I am having problems sending one soldier at a time. help would be appreciated.

while True:
    enemies = hero.findEnemies()
    enemy = hero.findNearest(enemies)
    friends = hero.findFriends()
    # Send the first soldier of the friends array towards the enemy.
    firstFriend = friends[0]
    # i in range(1, n) starts the index at the second element!
    for i in range(1, len(friends)):
        friend = friends[i]
        # Command the remaining soldiers to run away!
        hero.command(friends[3], "move", {"x": 29, "y": 34})
        hero.command(friends[9], "move", {"x": 41, "y": 55})

1 Like

A couple of things:

  1. You’ve defined a variable, firstFriend but don’t use it for anything. You don’t need that anyway.
# Send the first soldier of the friends array towards the enemy.
  1. You’ve not checked to see if there are any enemies and not commanded any of your friends to attack them if there are any. Just command friends[0] to do it.
# Command the remaining soldiers to run away!

Then command the rest, friends[i], to a defined retreat position. You define a single friend as a variable but never call it anywhere. You don’t need that either. You can command all of the remaining soldiers with a single line using friends[i].

Thank you very much
i beat the level

1 Like
while True:
    enemies = hero.findEnemies()
    enemy = hero.findNearest(enemies)
    friends = hero.findFriends()
    
    # Send the first soldier of the friends array towards the enemy.
    for  i in range(0, len(friends)):
        friend = friends[1]
        hero,command(friend, "move", {"x":16,"y":16})
        pass
    # i in range(1, n) starts the index at the second element!
    for i in range(1, len(friends)):
        friend = friends[i]
        # Command the remaining soldiers to run away!
        hero.command(friend, "move", {"x":30, "y":36})

could someone tell me what am i doing wrong … I’ve been at it for the past couple hours …
I mean ,just one soldier is moving towards the robots and after it dies … no other takes it’s place

1 Like

You don’t need to do for I in range(0, len(friends): at the start you just need to command friends[0] to go towards the enemy without a for loop or anything apart from hero.command(the person you want to command, "move", wherever you want him to go). The rest is right.

2 Likes

solved it , thank you kindly sir ! :smiley:

1 Like