Hi, I am struggling witha return statement.
Here is my code.
Can someone tell me what i did wrong? My hero doesnt have an error, but isnt summoning.
Code Here.
summonTypes = ['soldier', 'soldier', 'archer', 'decoy']
def summon():
type = summonTypes[len(hero.built) % len(summonTypes)]
return type
def commandPeasant():
friends = hero.findFriends()
for friend in friends:
if friend.type == 'peasant':
if (summon == 'decoy') and hero.gold > 25:
hero.command(friend, "buildXY", 'decoy', friend.pos.x, friend.pos.y)
else:
items = hero.findItems()
item = friend.findNearest(items)
if item:
hero.command(friend, "move", item.pos)
def commandSoldier():
friends = hero.findFriends()
for friend in friends:
if friend.type == 'archer':
enemies = hero.findEnemies()
target = friend.findNearest(enemies)
if target:
hero.command(friend, "attack", target)
def commandArcher():
friends = hero.findFriends()
for friend in friends:
if friend.type == 'soldier':
targets = hero.findByType("archer", hero.findEnemies())
target = friend.findNearest(targets)
if target:
hero.command(friend, "attack", target)
else:
enemies = hero.findEnemies()
enemy = friend.findNearest(enemies)
if enemy:
hero.command(friend, "attack", enemy)
def T():
if (summon == 'soldier') and hero.gold > 20:
hero.summon("soldier")
if (summon == 'archer') and hero.gold > 25:
hero.summon('archer')
def attack():
item = hero.findNearestItem()
if item:
hero.move(item.pos)
while True:
attack()
commandSoldier()
commandPeasant()
commandArcher()
T()
summon()