[SOLVED] Hunting Party help (Python)

can someone please tell me how to get my troops to move im confused on that, here is my code so far

# You can use findNearestEnemy() on your soldiers to get their nearest enemy instead of yours.
while True:
    friends = hero.findFriends()
    # Use for-loop and for each friend:
    for friends in friends:
        # If they see an enemy then command to attack.
        enemy = hero.findNearestEnemy()
        # Command to move east by small steps.
    else:
        hero.command(friend, "move", target)
2 Likes

Put 4 spaces before those lines. And try to check if the enemy exists and then attack it before the else. And you forgot to say what position is in the target variabile. Do you want me to show you what target should be?

Andrei

1 Like

yes please (20 characters)

2 Likes

Ok. Here it is:
target = {“x”: friend.pos.x + 1, “y”: friend.pos.y}

Andrei

1 Like

when i added it to the code the screen immediately showed this

2 Likes

You can delete the target =. And after you find out the enemy check if it exists and if so, attack it. After that put the else (inside the for loop).

Andrei

1 Like

You indented the line too far.

1 Like

@dedreous i didnt indent at all

2 Likes

Here put friend instead of hero.

Andrei

1 Like

Here you have a error. Try

for friend in friends

So the code will run corectly.

Andrei

1 Like

the screen is still showing this

2 Likes

Try to correct this too.

Andrei

1 Like

sorry what do you want me to do? do you want me to indent the else?

2 Likes

So, put an if ststement and check if enemy exists and if so, command the friend to attack. After that put the else but inside the for loop.

Andrei

1 Like

so you want it like this?

if enemy = friend.findNearestEnemy():
            hero.command(friend, "attack", target)
2 Likes

here is all the code

# You can use findNearestEnemy() on your soldiers to get their nearest enemy instead of yours.
while True:
    friends = hero.findFriends()
    # Use for-loop and for each friend:
    for friend in friends:
        # If they see an enemy then command to attack.
        if enemy = friend.findNearestEnemy():
            hero.command(friend, "attack", target)
        # Command to move east by small steps.
        else:
            hero.command(friend, "move", {“x”: friend.pos.x + 1, “y”:    friend.pos.y})
2 Likes

Here attack the enemy.

Andrei

1 Like

2 Likes

Gtg sorry. :cold_sweat:

Andrei

2 Likes

@dedreous can u help then?

2 Likes