Sarven Siege meets... unexpected error


#1

In coming back to this older level with newer skills and equipment, I was hoping to massacre the evil ogres with a combo of summoned archers and soldiers by using slightly modified code from Steelclaw Gap.

My error is commented in the code below.

I summon troops right off the bat (wearing Boss Star II), so I’m surprised by the error message. Is it because I concatenated the two troop types (to avoid the error on commanding accidentally the towers)?

// Defend your towers in this replayable challenge level!
// Step on an X if you have 20 gold to build a soldier.
var defendPoints = [{"x": 84, "y": 22},{"x": 84, "y": 51},{"x": 84, "y": 78}];
var summonTypes = ["soldier", "soldier", "solier", "archer", "archer", "archer"];

this.pickUpNearestCoin = function(){
    var items = this.findItems();
    var nearestCoin = this.findNearest(items);
    if (nearestCoin) {
        this.move(nearestCoin.pos);
    }
};

this.summonTroops = function(){
    var type = summonTypes[this.built.length % summonTypes.length];
    if (this.gold >= this.costOf(type)) {
        this.summon(type);
    }
};

this.commandTroops = function(){
    var friends = this.findByType("soldier") + this.findByType("archer");
    for(var friendIndex = 0; friendIndex < friends.length; friendIndex++){
        var friend = friends[friendIndex];
        var point = defendPoints[friendIndex % defendPoints.length];
// Error on line below: "Hero placeholder needs something to command"
        this.command(friend, "defend", point);
    }
};
loop {
    this.pickUpNearestCoin();
    this.summonTroops();
    this.commandTroops();
}

#2

The third element should be soldier and not solier.

But I can’t find any other errors… must be there (I have little experience with code)


#3

Yeah, I believe concatenating lists like that doesn’t work. Just use an if-statement.

if (friend.type !== "arrow-tower") {
   ...

#5

Thanks, that did the trick!

Evil concatenations!!!


#6

By the way, you can concat arrays using the concat method. E.g.:

var friends = this.findByType("soldier").concat(this.findByType("archer"));