Store

An object that can contain resources in its cargo.

There are two types of stores in the game: general purpose stores and limited stores.

The Store prototype is the same for both types of stores, but they have different behavior depending on the resource argument in its methods.

You can get specific resources from the store by addressing them as object properties:

console.log(creep.store[RESOURCE_ENERGY]);

getCapacity ([resource])

if(creep.store[RESOURCE_ENERGY] < creep.store.getCapacity()) {
    goHarvest(creep);
}

Returns capacity of this store for the specified resource. For a general purpose store, it returns total capacity if resource is undefined.

parameter type description
resource
optional
string

The type of the resource.

Return value

Returns capacity number, or null in case of an invalid resource for this store type.

getFreeCapacity ([resource])

if(structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0) {
    creep.transfer(structure, RESOURCE_ENERGY);
}

Returns free capacity for the store. For a limited store, it returns the capacity available for the specified resource if resource is defined and valid for this store.

parameter type description
resource
optional
string

The type of the resource.

Return value

Returns available capacity number, or null in case of an invalid resource for this store type.

getUsedCapacity ([resource])

if(Game.rooms['W1N1'].terminal.store.getUsedCapacity() == 0) {
    // terminal is empty
}

Returns the capacity used by the specified resource. For a general purpose store, it returns total used capacity if resource is undefined.

parameter type description
resource
optional
string

The type of the resource.

Return value

Returns used capacity number, or null in case of a not valid resource for this store type.