Hunting Party - stuck! (Python)

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

i need help with my code

Hi Manuel_Morales,

Two things:

Firstly, read this again:

At the moment you’ve set your enemy variable to what the hero sees.

Secondly, I had more success when I put an ‘else’ before the hero.command statement. I also needed to play about with the length of the step each time.

Cheers,

Jenny

it says that the parenthesis must match o line 13

I don’t know which your line 13 is (depends on how many comments you’ve put in). But check all your (, ), { and } to make sure they’ve all got a partner! Or post a screenshot of your code if you can’t work it out.

Jenny

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

you put a comma after the friend.pos
it should be

friend.pos.y

What @Eric_Tang says should sort out the error code.

For this line here:

you need to change to enemy = friend.findNearestEnemy(), and you need to have the line inside the for loop, so that each friend is instructed to find their enemy.

Jenny

thanks a lot i got it!!