Please help on Mixed Unit Tactics{SOLVED}

I am constantly getting an error saying i need an object
here is my code.

# Practice using modulo to loop over an array

# Choose the mix and order of units you want to summon by populating this array:
summonTypes = ["soldier", "archer", "soldier", "archer", "soldier", "archer"]

def summonTroops():
    # Use % to wrap around the summonTypes array based on len(hero.built)
    type = summonTypes[len(hero.built) % len(summonTypes)]
    coin = hero.findNearest(hero.findItems())
    if hero.gold >= hero.costOf(type):
        hero.summon(type)
    else:
        hero.move(coin.pos)

def commandTroops():
    friends=hero.findFriends()
    for friend in friends != 'palisade':
        enemies=hero.findEnemies()
        enemy=soldier.findNearestEnemy()
        if enemy:
            hero.command(friend, "attack", enemy)

while True:
    summonTroops()
    commandTroops()
    

I have no idea what i did wrong.

Which line is it giving you an error on? Also can you post a screenshot of the code in the game?

I noticed a problem. Instead of

for friend in friends != 'palisade':

you should have:

for friend in friends:
        if friend != "palisade":

Also, I don’t think

enemies = hero.findEnemies()

is necessary. Start with that, and if it still isn’t working, let me know.

you also haven’t checked whether there’s a coin.
:lion:

ok here is my screen.

thank you it worked for some reason, i still don’t know why i got the error tho.