Hunting Party - stuck! (Python)


#1

Okay so here is my code

friends = hero.findFriends()

for friend in friends:
    enemy = friend.findNearest(friend.findEnemies())
    if not enemy:
        hero.command(friend, "move", {'x': friend.pos.x + 24, 'y': friend.pos.y})
    else:
        hero.command(friend, "attack", enemy)

I know the for loop is going to loop over each friend. I also tried it this way:

friends = hero.findFriends()

for friend in friends:
    enemy = friend.findNearest(friend.findEnemies())
    if enemy:
        hero.command(friend, "attack", enemy)
    else:
        hero.command(friend, "move", {'x': friend.pos.x + 24, 'y': friend.pos.y})

In each case all of my units move 24 units to the right and then the top units stand there and get attacked. I’m not sure what to do and unfortunately I’m really lost. I can’t figure out exactly what it’s asking me and the hints aren’t helping. Please advise.


#2

From the hints:
HuntParty01

24 is WAY too much. Try putting a decimal point in front of that value. Then keep adjusting the number until it works.

BTW, your second code post should work, IF you put the whole thing (all of it) in a loop.


#3

All that happens when I change it is they move forward less and then stop.


#4

it stops because it’s not looping through the code. There is no loop. Try while True for the whole thing.


#5

That’s what I just did. I saw you adjust your earlier comment. That seems to be working but it’s being really laggy. Well, some troops died, but the while True loop fixed it. Thank you so much. I feel like I’m losing my mind today and this level was just the icing on the cake.


#6

now adjust that numeric value until it works and no one dies so you get the bonus.


#7

What do you want? Mk see ya.