Hunting party, I am hunting for answers!

Is the problem in

for friend in friends:

Before you find the friend’s nearest enemy, and after your for loop, you need to check if friend exists.

for friend in friends:
    if friend:
        friendAttackEnemy = friend.findNearestEnemy()
        if friendAttackEnemy:
            #command a friend to attack friendAttackEnemy
        else:
            #command a friend to move to the right
while True:
    friends = hero.findFriends()
    enemy = hero.findNearestEnemy()
    # Use for-loop and for each friend:
    for friend in friends:
        if friend:
            friendAttackEnemy = friend.findNearestEnemy()
            # If they see an enemy then command to attack.
            if friendAttackEnemy:
                hero.command(friend, "attack", enemy)
            # Command to move east by small steps.
            else:
                hero.command(friend, "move", friend.pos.x, friend.pos.y + 1)

Command them to attack friendAttackEnemy not enemy.

1 Like

Oh, ok I will, that makes a lot of sense.

Now the problem is in

hero.command(friend, "move", friend.pos.x, friend.pos.y + 1)

This needs to be {"x": friend.pos.x+1, "y": friend.pos.y}.

1 Like

Ah, hey, do you like my title?

That is off-topic.

I guess it is. Now all my “soldiers” are ramming into the trees above them!

blob:chrome-untrusted://media-app/518f425a-1086-44a1-a7ca-56f582d780ee

Well they will ram into the trees if you increase the y position of the friends by one. You need to increase the x position of the friends by one.

2 Likes

Sorry about that post, I was trying to send a screenshot, I will add to the x.

Thank you, that WORKED!

You should mark the solution of the post that helped you.

1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.