SOS!!!
-
Why donot in work?: var roleMule = { run: function(creep) {
if(creep.memory.mule && creep.store[RESOURCE_ENERGY] == 0) { creep.memory.muleing = false; } if(!creep.memory.mule && creep.store.getFreeCapacity() == 0) { creep.memory.muleing = true; } var targets = creep.room.find(FIND_STRUCTURES, { filter: (structure) => { return (structure.structureType == STRUCTURE_EXTENSION || structure.structureType == STRUCTURE_SPAWN || structure.structureType == STRUCTURE_TOWER) && structure.store.getFreeCapacity() > 0; } }); var containers = creep.room.find(STRUCTURE_CONTAINER, { filter: (structure) => { return (structure.structureType == STRUCTURE_CONTAINER) && (structure.store[RESOURCE_ENERGY] > 0); } }); if(creep.memory.muleing) { if(targets.length > 0) { if(creep.transfer(targets[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) { creep.moveTo(targets[0]); } } } else { if(containers.length > 0) { if(creep.withdraw(containers[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) { creep.moveTo(containers[0]); } } } }
};
module.exports = roleMule;
-
@telegraffony said in SOS!!!:
store.getFreeCapacity()
Im not sure why this is as it feels off... but if you call store.getFreeCapacity() without an resource type argument on a structure that can only store certain types of resource (in this case, spawns, extensions, towers) will return 0.
You need to do
store.getFreeCapacity(RESOURCE_ENERGY)
instead.
-
Please fix that. What's your code supposed to do? What's its behaviour now?
http://www.catb.org/~esr/faqs/smart-questions.html
And it's better to ask these basic questions on slack #help channel.
The first issue I spotted is that your first couple of lines are using both
creep.memory.mule
andcreep.memory.muleing
.
-
And the second one is as what @trebbettes said.
-
Well. It is a mule, and it's currently "muleing."
.getFreeCapacity(resource); is documented. For non general stores, you need to specify what you want the free capacity of.
The reason for this is simple. What if you have something with a store that accepts only a subset of a few items? Like a lab? Or a nuker? Labs can hold 5K TOTAL, but 3K of it must be that lab's mineral resource, and 2K of it must be energy. You have to tell it which you want the free capacity of for it to be meaningful at all.