Hunting Party coding help

I am stuck on Hunting Party, mountain level. This is my code:

def spawn():
    hero.move(hero.pos)
    hero.move(hero.pos)
    hero.move(hero.pos)
    hero.move(hero.pos)
    hero.move(hero.pos)
    hero.moveXY(44, 67)
    while enemy:
        if hero.isReady("bash"):
            hero.bash(enemy)
        elif friend.health < 10:
            hero.consecrate()
        else:
            hero.attack(enemy)
        
pet.on("spawn", spawn)
while True:
    friends = hero.findFriends()
    # Use for-loop and for each friend:
    for i in range(len(friends)):
        # If they see an enemy then command to attack.
        friend = hero.findNearest(hero.findFriends())
        enemy = friend.findNearestEnemy()
        if enemy:
            hero.command(friend, "attack", enemy)
            # Command to move east by small steps.
        else:
            y = friend.pos.y
            x = friend.pos.x + 1000
            hero.command(friend, "move", {"x": x, "y": y})

Wait, are we talking about the same hunting party? Does your level look like this:
image
-Grzmot

1 Like

yes, it is this level.

also, my code had to be reset because of infinite loop…

Okay, It looks like you have a very different strategy than what the level wants you to do. Try using a while loop and command your friends to attack an enemy if there is one. If not, try moving them forward. It should look something like this:

while True:
    friends = hero.findFriends()
    for friend in friends:
        (Tell them to find an enemy)
        if enemy:
            (command them to attack the enemy)
        else:
            (Command them to move forward)

Hope this helps!
-Grzmot

1 Like

uhh, there is a weird error on my code. it says that “enemy” is not a unit…

Is it the same code that you posted before or is it edited now?
-Grzmot

edited… and the original code in

hero.command(friend, "attack", enemy)
1 Like

I think that the issue might be coming from this:

If you want to use this kind of loop, try changing the second part to: friend = friends[i] so it will cycle through all of your friends. Hope this helps!
-Grzmot

1 Like

before, it worked. now it doesn’t…

1 Like

Could you show me your full updated code now?
-Grzmot

1 Like
while True:
    friends = hero.findFriends()
    # Use for-loop and for each friend:
    for i in range(len(friends)):
        # If they see an enemy then command to attack.
        friend = friends[i]
        enemy = friend.findNearestEnemy
        if enemy:
            hero.command(friend, "attack", enemy)
            # Command to move east by small steps.
        else:
            y = friend.pos.y
            x = friend.pos.x + 10
            hero.command(friend, "move", {"x": x, "y": y})

AND THEN IT HAS A ERROR SAYING THAT ENEMY IS A FUNCTION

1 Like

Forgot the parenthesis :upside_down_face:

1 Like

oooof (20 characters)

1 Like

Does it work now?
-Grzmot

1 Like

yes, it works perfectly

but too bad the bonus is hard to achieve

Bonus isn’t too hard to actually get, try adjusting this number:

(Hint: it should be lower than 10)
Hope this helps!
-Grzmot

I did 5 and it did not work…

Try for lower… If you don’t succeed the first time try again
-Grzmot