Timber turncoat: cant command soldiers

when my hero tries to command my soldier
he just stands freezes and i get an error

while True:
    # Collect gold.
    item = hero.findNearestItem()
    if item:
        hero.moveXY(item.pos.x, item.pos.y)
    # If you have enough gold, summon a soldier.
    if hero.gold > hero.costOf("soldier"):
        hero.summon("soldier")
    # Use a for-loop to command each soldier.
    for friend in hero.findFriends():
        if friend.type == "soldier":
            enemy = friend.findNearestEnemy()
            hero.command(friend, "move", (47, 52)
            # If there's an enemy, command her to attack.
            if enemy:
                hero.command(friend, "attack", enemy)
            elif soldier.health < 100:
                friend.moveXY(6, 47)
            # Careful! If your soldiers are defeated, a warlock will appear!
            # Otherwise, move her to the right side of the map.
                        

can you guys help me find out what the problem is
and how to command my soldiers
cause i havent played in a while so i forgot a bit

Try if friend and friend.type == "soldier":

1 Like

The problem is here, you forgot the closing bracket, and to command the soldier to move to a position, the last parameter should be a dictionary having both the values of x and y

Hint:

hero.command(friend, "move", {"x": 47, "y":52})

i believe this should be friend.health

this should be a command, i dont think it is possible to control the unit directly

1 Like

Also, here you can’t command like this.
Try hero.command(friend, "move", {"x": 6, "y":47}

1 Like

Thanks for the reply
Ima change my code after swimming
And @Aya the error duck said that instead of friends.health i needed to do soldier.health

hero.command(friend, "move", {"x": 6, "y":47}), not friend.moveXY(6, 47), you can’t control units directly
and friend.health not soldier.health, soldier is not defined

1 Like