所以我创造了一个守卫蠕变;
Game.spawns.Spawn1.createCreep([Game.ATTACK, Game.ATTACK, Game.TOUGH, Game.TOUGH, Game.MOVE], "guard1", {role:"guard"});
然后我将此作为我的主要内容:
var harvester = require('harvester');
var guard = require('guard');
for(var nam in Game.creeps) {
var creep = Game.creeps[nam];
if(creep.memory.role == 'guard') {
guard(creep);
}
if(creep.memory.role == 'harvester') {
harvester(creep);
}
if(creep.memory.role == 'builder') {
if(creep.energy === 0) {
creep.moveTo(Game.spawns.Spawn1);
Game.spawns.Spawn1.transferEnergy(creep);
}
else {
var targets = creep.room.find(Game.CONSTRUCTION_SITES);
if(targets.length) {
creep.moveTo(targets[0]);
creep.build(targets[0]);
}
}
}
}
然后是守卫剧本
module.exports = function (creep) {
var targets = creep.room.find(Game.HOSTILE_CREEPS);
if(targets.length) {
creep.moveTo(targets[0]);
creep.attack(targets[0]);
}else{
creep.moveTo(Game.spawns.Spawn1);
}
}
它在本教程中运行良好,但现在在实际模拟中,它不起作用。
答案 0 :(得分:2)
我测试了你的脚本,他们实际上在生存模式下工作得很好。具体问题是什么?您是否检查过CPU时间是否用尽?