after a while of collecting coins, my hero just stops. then it goes into an infinity loop. please help.
while True:
coin = hero.findNearestItem()
if coin:
hero.move(coin.pos)
# If you have funds for a soldier, summon one.
if hero.gold > hero.costOf("soldier"):
hero.summon("soldier")
enemy = hero.findNearest(hero.findEnemies())
if enemy:
soldiers = hero.findFriends()
soldierIndex = 0
soldier = soldiers[soldierIndex]
# Loop over all your soldiers and order them to attack.
while soldier:
# Use the 'attack' command to make your soldiers attack.
#hero.command(soldier, "attack", enemy)
hero.command(soldier, "attack", enemy)
place this after the while loop
soldier = soldiers[soldierIndex]
and put this after the command
soldier = soldiers[soldierIndex]
then it should work
Hope this helps
# Gather coins to summon soldiers and have them attack the enemy.
while True:
coin = hero.findNearestItem()
if coin:
hero.move(coin.pos)
# If you have funds for a soldier, summon one.
if hero.gold > hero.costOf("soldier"):
hero.summon("soldier")
enemy = hero.findNearest(hero.findEnemies())
if enemy:
soldiers = hero.findFriends()
soldierIndex = 0
soldier = soldiers[soldierIndex]
# Loop over all your soldiers and order them to attack.
while soldierIndex < len(soldiers):
# Use the 'attack' command to make your soldiers attack.
#hero.command(soldier, "attack", enemy)
hero.command(soldier, "attack", enemy)
soldier = soldiers[soldierIndex]
soldier = soldiers[soldierIndex]
this must be on top of the command
soldier = soldiers[soldierIndex]
the other one delete it
and add soldierIndex += 1
behind the command also in the while loop