Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

[SOLVED] Hunters and Prey - friends wont attack{SOLVED}


my troops aren’t attacking, im getting a headache, and my chicken pot pie is over cooked…

so can anyone please tell me why my troops aren’t attacking, ive tried nothing and im all out of ideas.

in all seriousness, been working on it for a while and I cant figure it out.

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

def pickUpCoin():
    # Collect coins.
    coin = hero.findNearestItem()
    if coin:

def summonTroops():
    # Summon soldiers if you have the gold.
    if > hero.costOf("soldier"):
# 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(soldier):
    # Soldiers should attack enemies.
    enemy = soldier.findNearest(hero.findEnemies)
    if enemy:
        self.command(soldier, "attack", enemy)
    # Soldiers should attack enemies.

# 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(archer):
    enemy = archer.findNearest(hero.findEnemies)
    if enemy and archer.distanceto(enemy) < 25:
        self.command(archer, "attack", enemy)
        self.command(archer, "move", archer.pos)
while True:
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == "soldier":
            # This friend will be assigned to the variable soldier in commandSoldier
        elif friend.type == "archer":
            # Be sure to command your archers.


What area is this level in so i can find it easier


its ok, I figured it out, much appreciated though.