The code ducky says I have an infinite loop. Help:
// Gather coins to summon soldiers and have them attack the enemy.
while(true) {
var coin = hero.findNearestItem();
// Move to the nearest coin.
// Use move instead of moveXY so you can command constantly.
if (coin) {
hero.move(coin.pos);
}
// If you have funds for a soldier, summon one.
if (hero.gold > hero.costOf("soldier")) {
hero.summon("soldier");
}
var enemy = hero.findNearest(hero.findEnemies());
if (enemy) {
var soldiers = hero.findFriends();
var soldierIndex = 0;
var soldier = soldiers[soldierIndex];
// Loop over all your soldiers and order them to attack.
while (soldierIndex < soldiers.length) {
// Use the 'attack' command to make your soldiers attack.
hero.command(soldier, "attack", enemy);
}
}
}