Mixed-unit-tactics advise

Hi, somehow i get an error for this line:
if hero.gold >= hero.costOf(summonTypes[type]):

any help is appreciated, pls find the full code below. Kind regards

# Versuche, modulo mit einem loop auf ein array anzuwenden.

# Wähle Zusammensetzung und Reihenfolge der Einheiten, indem du das Array befüllst.
summonTypes = ["soldier", "archer", "soldier", "archer", "soldier", "archer", "soldier", "archer"]

def summonTroops():
    # Use % to wrap around the summonTypes array based on len(hero.built)
    #type = summonTypes[???]
    type = summonTypes[len(hero.built) % len(summonTypes)]
    if hero.gold >= hero.costOf(summonTypes[type]):
        hero.summon(summonTypes[type])
    hero.say("I should summon troops!")

def collectCoins():
    coin = hero.findNearestItem()
    if coin:
        hero.move(coin.pos)
        totalGold = totalGold + coin.value
        pass

def commandTroops():
    friends = hero.findFriends()
    for friend in friends:
        if friend.type != "palisade":
            enemy = hero.findNearestEnemy()
            if enemy:
                hero.command(friend, "attack", enemy)
while True:
    collectCoins()
    summonTroops()
    commandTroops()

3 Likes

Hi @Farmerama, and welcome to the forum! :partying_face:
Please, can you post the link to the level and what error do you have.

3 Likes

Try changing all the summonTypes[type] into type

1 Like

That worked easily, thanks a lot!

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