The bane of soldiers: Help needed


#1

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.?


#2

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


#3

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)):


#4

so how do I do it?:thinking:


#5

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

Read this post from another thread of yours.


#6

thanks! I beat the level!