Mixed Unit Tactics - Help - Python

Hi, every time I run my code I get an error that says “TypeError: Need an object”. The error doesn’t highlight any specific line, so I’m not sure how to fix it. 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", "soldier", "archer", "archer"]

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

def commandTroops():
    friends = hero.findFriends()
    for friend in friends != "palisade":
        enemy = friend.findEnemies()
        if enemy:
            hero.command(friend, "attack", enemy)
        else:
            hero.command(friend, "defend", hero)

while True:
    summonTroops()
    commandTroops()

If anyone can help, thank you!
ScreenClip

You haven’t defined coinPos

You should use friend.type

You have to command your friend to defend a position.

Enemy is an array, so you have to target the nearest from enemy.

2 Likes

Thank you!
P.S. for anyone who was getting the same error that I was, it seems that switching to using friend.type was the fix!

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