@threen said in Harvester Roll Help:
You can use a state which only changes when the creep is either completely full, or completely empty.
eg. (completely untested)
module.exports.loop = function () {
Game.spawns['Spawn1'].spawnCreep([WORK, CARRY, MOVE, MOVE], 'testCreep');
var mycreep = Game.creeps['testCreep'];
if (mycreep.store.getFreeCapacity() === 0) {
mycreep.memory.state = 'UPGRADE';
}
else if (mycreep.store.getUsedCapacity() === 0) {
mycreep.memory.state = 'HARVEST';
}
if (mycreep.memory.state === 'HARVEST') {
var energysource = mycreep.pos.findClosestByPath(FIND_SOURCES);
mycreep.moveTo(energysource);
mycreep.harvest(energysource);
}
else {
var homecontroller = mycreep.room.controller;
mycreep.moveTo(homecontroller);
mycreep.upgradeController(homecontroller);
}
}
Also, you'll get a much quicker response from the #help channel of Slack (https://screeps.slack.com/).
Is actually an interesting way, never thought.
@detox said in Transfer energy from spawn to controller:
let creep = _.filter(Game.creeps, function(c){ return c.getActiveBodyparts(WORK) > 0 && c.getActiveBodyparts(CARRY) > 0; })[0];
let source = creep.room.find(FIND_SOURCES)[0];
if(creep.store.getFreeCapacity() == 0) creep.memory.storing = true;
if(creep.store.getUsedCapacity() == 0) creep.memory.storing = false;
if(creep.memory.storing){
if(creep.pos.getRangeTo(creep.room.controller) <= 3) creep.upgradeController(creep.room.controller); else creep.moveTo(creep.room.controller);
} else {
if(creep.pos.getRangeTo(source) == 1) creep.harvest(source); else creep.moveTo(source);
}
I think.