Play Home Contribute GitHub Join Us Discourse Staff Members GitHub Contribution Guides Team

Please help on Mixed Unit Tactics{SOLVED}


#1

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.


#2

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


#4

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.


#5

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


#6

ok here is my screen.


#7

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