Can't use findInRange and filter?



  • Hello everyone,

    I'm trying to find a container with an extractor next to it, but it doesn't find any 😕

            if(null == thisRoom.memory.mineralContainer){
                let myExtractor = [];
                myExtractor = thisRoom.find(FIND_STRUCTURES, { filter: (a) => a.structureType == STRUCTURE_EXTRACTOR});
                if(myExtractor.length > 0){
                    let mineralContainer = myExtractor[0].pos.findInRange(FIND_STRUCTURES, {filter: (a) => a.structureType == STRUCTURE_CONTAINER}, 1);
                    if(mineralContainer.length > 0){
                        thisRoom.memory.mineralContainer = mineralContainer[0].id;
                    }
                }else{
                    thisRoom.memory.mineralContainer = null;
                }
             } 
    

    Isn't it possible to apply filters to findInRange? or is there something else am i missing?

    Thanks!!



  • Try moving the range before the filter.

    ☝


  • JBYoshi is correct.

    Looking at the docs, findInRange() takes a FIND_* constant as first argument, the range as second, and optional parameters (such as the filter) as third input.

    https://docs.screeps.com/api/#RoomPosition.findInRange



  • Works like a charm! Thank you guys!