Can anyone help me with my code, it doesn’t work.
while True:
# Move to the nearest coin.
# Use move instead of moveXY so you can command constantly.
hero.say("I need coins!")
if hero.gold < hero.costOf("soldier"):
while hero.gold < hero.costOf("soldier"):
items = hero.findItems()
nearest = hero.findNearest(items)
if nearest:
hero.say(hero.distanceTo(nearest))
hero.move(nearest.pos)
#If you have funds for a soldier, summon one.
if hero.gold > hero.costOf("soldier"):
hero.say("I should summon something here!")
hero.summon("soldier")
enemy = hero.findNearest(hero.findEnemies())
if enemy:
# Loop over all your soldiers and order them to attack.
soldiers = hero.findFriends()
soldierIndex = 0
if soldiers:
hero.say("soldiers")
while len(soldiers) > soldierIndex:
soldier = soldiers[soldierIndex]
if soldier:
hero.say("found one")
hero.command(soldier, "attack", enemy)
soldierIndex += 1