我正在尝试根据我在main中的变量中设置的设定数量限制在main中设置自动生成脚本。但是,由于某种原因,脚本执行异常执行。
脚本:
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);
}
}
}
最后的控制台输出显示其作为其支持但是脚本执行忽略了if语句执行为false的事实。
[8:17:20 PM] false
[8:17:20 PM] 2
[8:17:20 PM] 9
[8:17:20 PM]收割机产卵falied:-6
[8:17:23 PM] false
[8:17:23 PM] 2
[8:17:23 PM] 10
答案 0 :(得分:2)
哦,我的上帝.....刚刚注意到我正在为两者调用spawnHarvester函数。 LOL。