1
// 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>

有什么我遗漏的或者我做错了什么吗?

4

1 回答 1

0

我通过在外部过滤器之前(和外部)执行内部过滤器解决了这个问题。这也节省了一些时间,因为过滤器基本相同,不必多次执行(用于修复等其他操作)

于 2016-07-20T13:50:53.083 回答