I am trying to setup an auto spawning script in main based on a set number limit I have set in a variable earlier in main. However, for some reason the script execution is executing abnormally.
Script:
var roleHarvester = require('role.harvester');
var roleUpgrader = require('role.upgrader');
var roleSpawner = require('role.spawner');
var trashHandler = require('helper.trashHandler');
module.exports.loop = function () {
//Start by cleaning memory
trashHandler.run(Memory);
//Default Number of Creeps
var max_harvesters = 2;
var max_upgraders = 3;
for(var name in Game.creeps) {
var creep = Game.creeps[name];
if (creep.memory.role == 'harvester'){
roleHarvester.run(creep);
} else if (creep.memory.role == 'upgrader'){
roleUpgrader.run(creep);
}
}
var harvesters = _.filter(Game.creeps,(creep)=>creep.memory.role == 'harvester');
var upgraders = _.filter(Game.creeps,(creep)=>creep.memory.role == 'upgrader');
for (var name in Game.spawns){
var spawner = Game.spawns[name];
console.log(harvesters.length < max_harvesters);
console.log(max_harvesters);
console.log(harvesters.length);
if (harvesters.length < max_harvesters){
roleSpawner.spawnHarvester(spawner);
} else if (upgraders.length < max_upgraders){
roleSpawner.spawnHarvester(spawner);
}
}
}
The console outputs at the end show that its working as its suppoed to but that the script execution is ignoring the fact that the if statement is executing to false.
[8:17:20 PM]false
[8:17:20 PM]2
[8:17:20 PM]9
[8:17:20 PM]harvester spawn falied: -6
[8:17:23 PM]false
[8:17:23 PM]2
[8:17:23 PM]10
Oh my god..... Just noticed I was calling the spawnHarvester function for both. LOL.