# Gather coins to summon soldiers and have them attack the enemy.
while True:
# Move to the nearest coin.
# Use move instead of moveXY so you can command
enemy = hero.findNearestEnemy()
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")
if enemy:
soldiers = hero.findFriends()
soldierIndex = 0
soldier = soldiers[soldierIndex]
# Loop over all your soldiers and order them to attack
hero.command(soldier, "attack", enemy)
This is my code and it only lets one of the soldiers I summon attack at a time. therefore my hero keeps dying.