Search code examples
screeps

How To Find Number Of Extentions


I have tried Game.STRUCTURE_EXTENSION.length and Game.STRUCTURES.E.length, but these either cause an error, or are undefined - even though I have extensions.

Is there a global variable for extensions, or is there some way to find the number of extensions through a loop. Because i need my spawn to know how many extensions there are to determine what to spawn.


Solution

  • STRUCTURE_EXTENSION is just a number constant, not an array.

    In order to calculate the total number of extensions in a room where your spawn is located you can do the following:

    var extensions = Game.spawns.Spawn1.room.find(FIND_MY_STRUCTURES, {
      filter: { structureType: STRUCTURE_EXTENSION }
    });
    console.log(extensions.length);
    

    See Room.find method in documentaion.