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):
        if coin:

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

while True:

If anyone can help, thank you!

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.


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.