Bob
Bob

Reputation: 43

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.

Upvotes: 2

Views: 2169

Answers (2)

artch
artch

Reputation: 4545

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.

Upvotes: 4

DunknDonuts
DunknDonuts

Reputation: 1

Roll through your rooms, or you could just count one room.

var extensionCount = 0;
for(var roomName in Game.rooms) {
    extensionCount += Game.rooms[roomName].find(FIND_MY_STRUCTURES,{
        filter: function(object){return object.structureType === STRUCTURE_EXTENSION;
    }).length;
}

using room.find method

Upvotes: 0

Related Questions