// 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() {
}
// Define the function: pickUpNearestCoin
function PickuNearstCoin() {
}
var peasant = hero.findByType("peasant")[0];
while(true) {
summonSoldiers();
commandSoldiers();
pickUpNearestCoin();
}
help have erorr >> hero.command(friend, “attack”, enemy);
// 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() {
var friend = hero.findFriends();
var enemy = hero.findNearestEnemy();
if(enemy) {
hero.command(friend, "attack", enemy);
}
}
// Define the function: pickUpNearestCoin
function pickuNearstCoin() {
var item = hero.findNearestItem();
if (item) {
hero.move(item.pos);
}
}
var peasant = hero.findByType("peasant")[0];
while(true) {
summonSoldiers();
commandSoldiers();
pickuNearstCoin();
}
function commandSoldiers() {
var friend = hero.findFriends();
var enemy = hero.findNearestEnemy();
if(enemy) {
hero.command(friend, "attack", enemy);
}
}
Instead, try something like:
function commandSoldiers() {
for (let friend of hero.findFriends()) {
let enemy = friend.findNearest(hero.findEnemies());
if (enemy) hero.command(friend, "attack", enemy);
}
}