The Two Flowers Error message (Python)[SOLVED]

hi, could somone explain why i’m getting this error?
it says hero placeholder cant command type “peasant”. But im not commanding a peasant, im commanding a soldier.

here is the code and a screenshot.

# If the peasant is damaged, the flowers will shrink!

def summonSoldiers():
    if hero.gold >= hero.costOf("soldier"):
        hero.summon("soldier")

# Define the function: commandSoldiers
def commandSoldiers():
    for soldier in hero.findFriends():
        enemy = hero.findNearestEnemy()
        if enemy:
            hero.command(soldier, "attack", enemy)
# Define the function: pickUpNearestCoin
def pickUpNearestCoin():
    items = hero.findItems()
    nearestCoin = hero.findNearestItem()
    if nearestCoin:
        hero.move(nearestCoin.pos)
            

while True:
    summonSoldiers()
    commandSoldiers()
    pickUpNearestCoin()

the problem is you haven’t said you were commanding soldiers so the system doesn’t know.

2 Likes

hey eric, thanks for the response.
i thought i was by putting for for soldier in hero.findFriends():
doesnt for soldier define the soldier?

No it doesn’t. Because you have a array of all your friends and all your doing is making a variable for all your friends. You need to do a

if soldier.type == "soldier":
2 Likes

Thanks for that. The soldiers are now attacking. i cant pass the level like this but its a start.
many thanks :smiley:

(edit: i’ll leave it a while before checking the solution box in case i need to post something else. saves creating a new topic.)

1 Like

@Psyko2k You are always able to make a new topic if you need help so really there is no need for this one once you have solved it. I do appreciate that you want to keep this open but others may have already clicked on this topic and then off which means that only people that have not been on or @Eric_Tang will see this so do please check the tik box and make a new one if necessary thanks.

ok no problem. i’ll click solved. :slight_smile:

1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.