Summoning mercenaries with the flag better

In the level Restless Dead at Cloudrip Mt. I attempted to tie my summoning ability to when I drop the black flag so as to have the best timing and positioning. However, instead of summoning all of the soldiers at once like it would with a normal statement, it summons only 1 per flag drop.

I believe I lose vital seconds and army strength by repeatedly dropping the black flag to use up all my gold to attack the skeleton army. Anyone know how I can summon all?

// This level is supposed to be VERY hard! You may need a great strategy and or gear to complete it!

// Find and kill the yeti to gather his blood for the ritual
// You might want to gather the coins the yeti leaves behind, you'll need them to summon an army
// Stand at the summoning stone (red x) to begin summoning
// Now you just have to survive the undead hoard
this.followTheFlag = function(){
    var flagG = this.findFlag("green");
    if(flagG){
        this.pickUpFlag(flagG);
    }
};
// This function has your hero collect the nearest coin.
this.pickUpNearestCoin = function() {
    var items = this.findItems();
    var nearestCoin = this.findNearest(items);
    if(nearestCoin) {
        this.move(nearestCoin.pos);
    }
};

// This function has your hero summon a soldier.
this.summonSoldier = function() {
    // Dropping black flag starts summoning
    var flagB = this.findFlag("black");
    if(flagB){
        this.pickUpFlag(flagB);
        // Fill in code here to summon a soldier if you have enough gold.
        if(this.costOf("soldier") <= this.gold){
            this.summon("soldier");
        }
    }
};

// This function commands your soldiers to attack their nearest enemy.
this.commandSoldiers = function() {
    var friends = this.findFriends();
    for(var i=0; i < friends.length; i++) {
        var enemy = friends[i].findNearestEnemy();
        if(enemy) {
            this.command(friends[i],"attack", enemy);
        }
    }
};

// Hero attacks to thin the horde
this.heroAttack = function(){
    var horde = this.findEnemies();
    for(var h = 0; h < horde.length / 4; h++){
        var target = horde[h];
        if (this.isReady("electrocute") && this.canElectrocute(target) && this.distanceTo(target) < 21) {
            this.electrocute(target);
        }else if (this.canCast("chain-lightning", this.target)) {
            this.cast("chain-lightning", target);
        }else{
            this.attack(target);
        }
    }
};

loop {
    this.followTheFlag();
    this.pickUpNearestCoin();
    // Call summonSoldier here
    this.summonSoldier();
    // Call commandSoldiers here
    this.commandSoldiers();
    // Hero attacks here
    this.heroAttack();
}

Use a while-loop to do so. Like this:

this.summonSoldier = function() {
    // Dropping black flag starts summoning
    var flagB = this.findFlag("black");
    if(flagB){
        this.pickUpFlag(flagB);
        // Fill in code here to summon a soldier if you have enough gold.
        while (this.costOf("soldier") <= this.gold){
            this.summon("soldier");
        }
    }
}
2 Likes

One word change is all it took, thanks ChronistGilver!

Now if only I can find a way to stay alive to the very end.

ive tried your code, PixelAA, but do you know where to summon the soldiers? are you using ranger, warrior, or wizard?

thanks.

Please do not ask users questions a large amount of time later than their previous participation in the post.
It is likely that they will not answer your questions, making it a waste of time for everyone reading the revived thread.