嵌套过滤器不起作用
Nested filter doesn't work
// 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
}
});
上面的代码 returns 0 个建筑工地(应通过测试的 40 个建筑工地中),但每个建筑工地都通过了(外部)过滤器。
我还测试了内部过滤器(使用 .length == 0
):
console.log(<filter1>); // true
console.log(<filter2>); // true
console.log(<filter1>, <filter2>) // true true
console.log(<filter1> && <filter2>
我是否遗漏了什么或者我做错了什么?
我通过在外部过滤器之前(和外部)执行内部过滤器解决了这个问题。这也节省了一些时间,因为大部分相同的过滤器不必执行多次(对于修复等其他操作)
// 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
}
});
上面的代码 returns 0 个建筑工地(应通过测试的 40 个建筑工地中),但每个建筑工地都通过了(外部)过滤器。
我还测试了内部过滤器(使用 .length == 0
):
console.log(<filter1>); // true
console.log(<filter2>); // true
console.log(<filter1>, <filter2>) // true true
console.log(<filter1> && <filter2>
我是否遗漏了什么或者我做错了什么?
我通过在外部过滤器之前(和外部)执行内部过滤器解决了这个问题。这也节省了一些时间,因为大部分相同的过滤器不必执行多次(对于修复等其他操作)