Can't fill all of my extensions
-
Hi everyone, I am really new to screeps so this might sound like a basic issue. My problem is that my Harvesters fill the Spawn with energy and then they only fill 1 extension when there are 4 extensions left empty.
I was wondering how to fix that issue.
My code: var roleHarvester = {
/** @param {Creep} creep **/ run: function(creep) { if(creep.store.getFreeCapacity() > 0) { var sources = creep.room.find(FIND_SOURCES); if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) { creep.moveTo(sources[0], {visualizePathStyle: {stroke: '#ffaa00'}}); } } else { var targets = creep.room.find(FIND_STRUCTURES, { filter: (structure) => { return (structure.structureType == STRUCTURE_EXTENSION || structure.structureType == STRUCTURE_SPAWN) && structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0; } }); if(targets.length > 0) { if(creep.transfer(targets[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) { creep.moveTo(targets[0], {visualizePathStyle: {stroke: '#ffffff'}}); } } } }
};
module.exports = roleHarvester;
-
let me make sure. Is your problem that you want to fill extension first ?
If yes, i suggest your change your find targets code, a simple change is
const target = targets[targets.length - 1]; // take the last target, it must not be spawn
and then
if (creep.transfer(target, RESOURCE_ENERGY) === ERR_NOT_IN_RANGE) { creep.moveTo(target); }