// 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(peasant) {
var friends = hero.findFriends();
var enemy = hero.findNearestEnemy();
for (var i = 0; i < friends.length; i ++) {
var friend = friends[i];
if (enemy && friend.type == "soldier") {
hero.command(friend, "defend", peasant);
}
}
}
// Define the function: pickUpNearestCoin
function pickUpNearestCoin() {
var item = hero.findNearestItem();
if (item) {
if (hero.isReady("jump")) {
hero.jumpTo(item.pos);
}
else {
hero.move(item.pos);
}
}
}
var peasant = hero.findByType("peasant")[0];
function run(peasant) {
while(true) {
summonSoldiers();
commandSoldiers(peasant);
pickUpNearestCoin();
}
}
run(peasant);
keep getting infinite loops