// Handle repairing and attacking for towers
var towers = _.filter(Game.structures, (s) => STRUCTURE_TOWER);
for (let tower of towers) {
var closestWounded = tower.pos.findClosestByRange(FIND_MY_CREEPS, {
filter: (w) => w.hits < w.hitsMax
});
var closestHostile = tower.pos.findClosestByRange(FIND_HOSTILE_CREEPS);
var closestDamagedStructure = tower.pos.findClosestByRange(FIND_STRUCTURES, {
filter: (s) => s.hits < s.hitsMax && s.structureType != STRUCTURE_WALL
});
if(closestHostile) {
tower.attack(closestHostile);
}
if ((closestWounded) && (tower.energy > 250)) {
tower.heal(closestWounded);
}
/*if ((closestDamagedStructure) && (tower.energy > 990)) {
tower.repair(closestDamagedStructure);
}*/
}
This is all my code related to towers, I'm stumped as to why I keep getting this "TypeError: tower.attack is not a function
at Object.module.exports.loop (main:74:8)
at __mainLoop:1:52"
In my emails whenever an npc creep comes and wipes out my colony (well it wouldn't if my tower was working)
tower.repair() works just fine, so I can't understand why this error is showing.
Any help would be greatly appreciated!
PS: line 74 is tower.attack(closestHostile);
PPS: don't mind the commented out repair section, still working on making it periodic