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!