The bane of soldiers: Help needed

This, is the default code:

while True:
    enemies = hero.findEnemies()
    enemy = hero.findNearest(enemies)
    friends = hero.findFriends()
    # Send the first soldier of the friends array towards the enemy.
    
    # 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[i], "move", {"x": 29, "y": 34})

how do I # Send the first soldier of the friends array towards the enemy.?

1 Like

Because index 1 is the second unit in the array, what index would you use to find the first?

1 Like

You have your list of friends. It’s stored as the variable named friends.

Look at this line; it gives an example of how to command a single friend from the list of friends:

hero.command(friends[i], "move", {"x": 29, "y": 34})

i is a number that is determined by the line: for i in range(1, len(friends)):

1 Like

so how do I do it?:thinking:

You can simply replace the i in friends[i] with a number.

Read this post from another thread of yours.

thanks! I beat the level!