This is my code
while(true) {
// Move to the nearest coin.
// Use move instead of moveXY so you can command constantly.
hero.say("I need coins!");
var 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.say("I should summon something here!");
hero.summon("soldier");
}
var enemy = hero.findNearestEnemy();
if (enemy) {
var soldiers = hero.findFriends();
var soldierIndex = 0;
// Loop over all your soldiers and order them to attack.
while(soldierIndex < soldiers.length) {
var soldier = soldiers[soldierIndex];
// Use the 'attack' command to make your soldiers attack.
hero.command(soldier, "attack", enemy);
soldierIndex += 1;
}
}
}