The Two Flowers. Hero gets carried away by collecting coins


#1

So my hero gets carried away by collecting coins, and not summoning any troops. Is there any way to counter this. I know there’s at least one.
This is my code.

hero.summonSoldiers = function() {
    var friends = hero.findFriends();
    
    if (hero.gold === 20) {
        hero.summon("soldier");
        
    }
};

// Define the function: commandSoldiers

this.commandSoldiers = function() {
    var soldiers = hero.findByType("soldier");
    if (soldiers){
        for (var index = 0; index < soldiers.length; index++){
            var soldier = soldiers[index];
            var enemy = soldier.findNearestEnemy();
            if (enemy){
                hero.command(soldier, 'attack', enemy);
            }
        }
    }
};
// Define the function: pickUpNearestCoin
function pickUpNearestCoin() {
    var item = hero.findNearestItem();
    if (item) {
        hero.move(item.pos);
    }
}
var peasant = hero.findByType("peasant")[0];

while(true) {
    hero.summonSoldiers();
    hero.commandSoldiers();
    pickUpNearestCoin();
    
}

#2

Problem is here:

if (hero.gold === 20) {
        hero.summon("soldier");
        
    }

#3

I know, do you know how to counter it though.


#4

hero.gold is bigger or equal to 20


#5

wait, I solved it.
(Post needs 20 characters)