Hunters prey Level, archers don´t defend reindeers - Help!


#1

Hello coders! I need help:
This part of my code does not work:

def commandSoldier(soldier):
    # Soldaten sollen Feinde angreifen.
    for soldier in self.findFriends():
        enemy = soldier.findNearestEnemy()
        if enemy:
            self.command(soldier, "attack", enemy)
    pass
def commandArcher(archer):
    # Soldaten sollen Feinde angreifen.
    for archer in self.findFriends():
        enemy = archer.findNearestEnemy()
        if enemy:
            distance=archer.distanceTo(enemy)
            if distance<25:
                #self.command(archer, "move",{"x":20,"y":46})
                #self.command(archer, "attack", enemy)
        #else:


loop:
    pickUpCoin()
    summonTroops()
    friends = self.findFriends()
    for friend in friends:
        if friend.type == "soldier":
            # Dieser Freund wird zu den veränderlichen Soldaten in commandSoldier zugeordnet.
            commandSoldier(friend)
        if friend.type == "archer":
            commandArcher(friend)
            pass

The archers don´t wait to defend the reindeers, they run to the right and never come back. Who can help?
Sometimes I get the error message I can not command the Reindeers??


#2

You have a mess of loops.

Your functions don’t need loops in them as you are already looping through every unit you command. If it is a soldier, you command soldier, but in the command soldier function you try to command everything on your team.

Delete the loops in the functions.