Hunters and prey hero won't pick up coins

My hero was picking up coins before but I changed the code and now he won’t move. I feel as though he should be picking up coins. What’s wrong with my code?

def pickUpCoin():
    # Collect coins.
    item = hero.findNearestItem()
    if item:
        hero.moveXY(item.pos.x, item.pos.y)

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.findNearestEnemy()
    if enemy: 
        hero.command(soldier, "attack", enemy)

# 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.findNearestEnemy()
    distance = archer.distanceTo(enemy)
    if distance < 25:
        hero.command(archer, "attack", "enemy")
        hero.command(archer, "move", {"x":20, "y":65})
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.

1 Like

You probably need to input the unit you want to command into commandArcher() like you did with commandSoldier()
Sometimes the enemy isn’t defined; you will need to put an if statement around the line defining distance to check if there is actually an enemy.