[SOLVED] Stuck on hunting party

type or paste code here
```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
        hero.command(friend, "attack", enemy)
    # Command to move east by small steps.
    hero.command(friend, "move", {"x": friend.pos.x + 5, "y": friend.pos.y})

Try to format it again, deleting this:

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
hero.command(friend, “attack”, enemy)
# Command to move east by small steps.
hero.command(friend, “move”, {“x”: friend.pos.x + 5, “y”: friend.pos.y})

Can you try one more time?

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
        hero.command(friend, "attack", enemy)
    # Command to move east by small steps.
    hero.command(friend, "move", {"x": friend.pos.x + 5, "y": friend.pos.y})

Your code is well formated. Now I will tey to hwlp you solve the level.

Before that you forgot to put that in the variabile enemy is friend’s nearest enemy and check if it exists and only then attack.
Do you need any more assistance at this level?

so wat should I put in the command

hello can you show me wat to put in the command please

You need to command the friend to attavk the enemy only if the enemy exisis.
Do you need any more assistance at this level?

can you show me in code I mean

Ok here it is

enemy = friend.findNearestEnemy()
if enemy:
    #here command your friend to attack the enemy

Do you need any more assistance at this level?

wat do I put in this comand

 hero.command(friend, "move", {"x": friend.pos.x + 5, "y": friend.pos.y})

In an else to this if

Do you need any more assistance at this level?

can you show me wat it should look like I’m so confused

enemy = friend.findNearestEnemy()
if enemy:
    #command to attack
else:
    #command to move

Do you need any more assistance at this level?

1 Like

can you show me all of it together the code please

Put this

Instead of all of this( but don’t forget to command the friend)

Do you need any more assistance at this level?

while True:
    friends = hero.findFriends()
    # Use for-loop and for each friend:
    for friend in friends:
        enemy = friend.findNearestEnemy()
if enemy:
    hero.command(friend, "attack", enemy)
    # Command to move east by small steps.
else:
    hero.command(friend, "move", {"x": friend.pos.x + 5, "y": friend.pos.y})