What does RESOURCE_POWER refer to?



  • title. Trying to make it so my harvesters and such will ignore a Storage unit if it is full. I know it's a long shot, because I just started the game, and 'lol when will you have 1m energy?' But I'd like to anyway. Have a simulation going and can't figure it out. This is what I have so far, but if the storage unit is full with a mixture of energy and something else, it still tries to go for the storage unit because energy < capacity.

    structure.structureType == STRUCTURE_STORAGE &&
    ((structure.store[WHAT_DO_I_PUT_HERE?] + structure.store[OR_HERE?]) < structure.storeCapacity)



  • RESOURCE_POWER refers to the resource type "power". It is a resource type you can harvest from randomly spawned power banks in the corridor rooms.

    The "store" property is an object with properties just like Game.creeps is. This means you can loop the content of store just like you probably do with creeps.

    for (var creepName in Game.creeps) {

    var creep = Game.creeps[creepName];

    }

    For store it would be like this:

    var total = 0;

    for (var resourceType in structure.store) {

    var amount = structure.store[resourceType];

    total = total + amount;

    }

    With that being said. In screeps we have access to a set of utility functions from a library called lodash. You should look at the _.sum() function. My loop above can be written like.

    var total = _.sum(structure.store);

     

    https://lodash.com/docs/4.17.4



  • Ah, thanks, I didn't know "Power" was a thing that actually existed. Thanks for clarifying. I kind of assumed power was the sum already (and realized it wasn't when it wasn't working) Thanks for the pointers.