In Ace of Coders, I tried to do this
var friends = this.built;
var soldiers = friends.findByType("soldier");
to separate my units. However, I get this error: tmp35[tmp36 is not a function]
Any suggested fixes?
In Ace of Coders, I tried to do this
var friends = this.built;
var soldiers = friends.findByType("soldier");
to separate my units. However, I get this error: tmp35[tmp36 is not a function]
Any suggested fixes?
2 posts were merged into an existing topic: Ace of Coders - Questions & Feedback
A post was merged into an existing topic: Ace of Coders - Questions & Feedback
this.built
is an array and does not have a findByType
method. Your hero has the findByType
method. The code should be:
var soldiers = this.findByType('soldier', this.built);
// OR:
var soldiers = this.built.filter(function(unit) { return unit.type === 'soldier'; });
However, note that this.built
includes dead units. If you want only the alive ones you can use:
var soldiers = this.findByType('soldier', this.findFriends());
// OR:
var soldiers = this.built.filter(function(unit) {
return unit.type === 'soldier' && unit.health > 0;
});