Can't find containers on my map



  • I am trying to get my creeps to withdraw energy from my containers to move to extensions for spawning, but my code isn't finding any of the containers, even though they're full and the creeps are standing right next to them, a search for containers or a call to withdraw returns null. These are the two types of code I tried. var targets = creep.room.find(FIND_STRUCTURES, {

                filter: (structure) => {
                    return 
                        (structure.structureType == STRUCTURE_CONTAINER && structure.store[RESOURCE_ENERGY] > 0);}}
                )
    
            var resource = creep.pos.findClosestByRange(STRUCTURE_CONTAINER);


  • The first code segment returns an array of the non-empty containers, you would need to use targets[n] to determine the one you want.

    The second won't work, as "STRUCTURE_CONTAINER" isn't one of the FIND constants. You need to use "FIND_STRUCTURES" then filter for the one you want. THAT one returns a single object.


  • Dev Team

    Also, make sure you're using FIND_STRUCTURES, not FIND_MY_STRUCTURES because containers (same to walls and roads) are not owned.