Hunting Party (Python) Bug or User Error?

Hey there, trying to complete the level Hunting Party, and everything I’ve been trying is giving me errors. Any help would be appreciated! Here is my code:

# Command your troops to move east and attack any ogres they see.
# Use for-loops and findFriends.
# You can use findNearestEnemy() on your soldiers to get their nearest enemy instead of yours.

friend = hero.findFriends()
for a in friend:
    enemy = friend[a].findNearestEnemy()
    movement = ({'x':friend[a].pos.x+2,'y':friend[a].pos.y})
    hero.command(friend[a], "move", movement)
    if enemy:
        hero.command(friend[a], "attack", enemy)
    a +=1
movement = ({'x':friend[a].pos.x+2,'y':friend[a].pos.y})

I don’t think you need the regular parentheses in that line.

Actually that line seems to be fine. I made some progress by changing the for loop from:

for a in friend:

to

for a in range(len(friend)):

Now my minions will run to their designated locations but won’t stop to kill any enemies. Progress is being made!

Okay, I was an idiot (surprise!). Code loop worked just fine with the “for a in range(len(friend)):” change. I simply forgot to include the game loop (while True:). :roll_eyes:

2 Likes