// Build structures
var structs = curRoom.find(FIND_CONSTRUCTION_SITES, {
filter: (structure) => {
return
_.filter(Memory.jobs.worker.normal,
(job) => {
return job.id == structure.id;
}).length == 0 // Test if this structure is already in the queue
&& _.filter(Game.creeps,
(creep) => {
return creep.memory.curJob != undefined && creep.memory.curJob.id == structure.id;
}).length == 0; // Test if a creep is already working on this structure
}
});上面的代码返回0个建筑工地(应该通过测试的40个建筑工地中),但每个建筑工地都通过(外部)过滤器。
我还测试了内部过滤器(使用.length == 0):
console.log(<filter1>); // true
console.log(<filter2>); // true
console.log(<filter1>, <filter2>) // true true
console.log(<filter1> && <filter2>是我遗漏了什么,还是我做错了什么?
发布于 2016-07-20 21:50:53
我通过在外部过滤器之前(和外部)执行内部过滤器解决了这个问题。这也节省了一些时间,因为过滤器几乎是相同的,不需要多次执行(对于其他操作,如修复等)
https://stackoverflow.com/questions/38470033
复制相似问题