i don’t understand where i’m wrong. some one help me
// If the peasant is damaged, the flowers will shrink!
function summonSoldiers() {
if (hero.gold >= hero.costOf("soldier")) {
hero.summon("soldier");
}
}
// Define the function: commandSoldiers
function commandSoldiers() {
let soldiers = hero.findFriends();
for(let i = 0; i < soldiers.length; i++) {
let enemy = soldiers[i].findNearestEnemy();
if(enemy) {
hero.command(soldiers[i],"attack", enemy.pos);
}
}
}
// Define the function: pickUpNearestCoin
function pickUpNearestCoin() {
let item = hero.findItems();
let coin = hero.findNearest(item);
if (coin) {
hero.move(coin.pos);
}
}
var peasant = hero.findByType("peasant")[0];
while(true) {
summonSoldiers();
commandSoldiers();
pickUpNearestCoin();
}