[SOLVED]Help in Hunter's prey

Yeah and he should put in friend for these places and do what Lydia said

So you will have to delete

This as Falcons118 has said.
And change

Both to friends as milton.jinich has said
Lydia

huh I thought you guys told me to delete enemy = soldier.findNearestEnemy()

enemy = archer.findNearestEnemy()`

Yes delete that, and change

but where? (20 chars)

From here @Ryan_Wong

delete the stuff Lydia said in the post above your post ^^^^

Here and here(20 char)

no which code? since there are a lot of soldier archer

In this area(20 char)

delete here

and change to friend here

And it is in the area that I just posted

now when I added that it says:


for line 33: if enemyDistance < 25:

@milton.jinich and @Lydia_Song I think that you guys got this covered since you know more Python than me so Ill leave it to you two

try doing

if hero.distanceTo(enemy) <= 25:

You need to define enemyDistance = archer.findDistanceTo(enemy)
Lydia

now it says:


when I added what @milton.jinich said

Post your recent code know.

Try doing what I said
Lydia

@Lydia_Song I didn’t get what you said

@milton.jinich here is my code:

# Ogres are trying to take out your reindeer!
# Keep your archers back while summoning soldiers to attack.

def pickUpCoin():
    # Collect coins.
    item = hero.findNearestItem()
    if item:
        hero.move(item.pos)
    pass

def summonTroops():
    # Summon soldiers if you have the gold.
    if hero.gold > hero.costOf("soldier"):
        hero.summon("soldier")
    pass
    
# This function has an argument named soldier.
# Arguments are like variables.
# The value of an argument is determined when the function is called.
def commandSoldier():
    for soldier in hero.findFriends():
        enemy = soldier.findNearestEnemy()
        if enemy:
            hero.command(soldier, "attack", enemy)
    pass

# Write a commandArcher function to tell your archers what to do!
# It should take one argument that will represent the archer passed to the function when it's called.
# Archers should only attack enemies who are closer than 25 meters, otherwise, stay still.
def commandArcher():
    for archer in hero.findFriends():
        enemy = archer.findNearestEnemy()
        if hero.distanceTo(enemy) <= 25:
                
            if friend.type == "archer":
                hero.command(friend, "attack", enemy)
                
            else:
                if enemyDistance > 25:
                    
                    hero.command(friend, "move", friend.pos)
        
    pass

while True:
    pickUpCoin()
    summonTroops()
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == "soldier":
            # This friend will be assigned to the variable soldier in commandSoldier
            commandSoldier(friend)
        elif friend.type == "archer":
            # Be sure to command your archers.
            commandArcher(friend)
            pass

For this one you should do

This

 if hero.distanceTo(enemy) >= 25: