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()