Reputation: 23
Exactly what the title says. I've tried quite a few different ways but "creep.transferEnergy(Game.controller);" is the only one that didn't return an error.
Upvotes: 2
Views: 856
Reputation: 1
I had real trouble with this. The answer provided does do what you want, but... Each Game tick checks to see if the current level of energy being carried by the creep is less than the current capacity the creep can hold.
So, after upgrading once, the first check, makes the creep seek energy. Your source could be a distance away. What we want to do is deplete the current stored energy, then seek energy when empty.
if(creep.memory.upgrader && creep.carry.energy == 0) {
creep.memory.upgrader = false;
}
if(!creep.memory.upgrader && creep.carry.energy == creep.carryCapacity) {
creep.memory.upgrader = true;
}
if(creep.memory.upgrader) {
if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) {
creep.moveTo(creep.room.controller);
}
} else {
var source = creep.pos.findClosestByRange(FIND_SOURCES);
if(creep.harvest(source) == ERR_NOT_IN_RANGE) {
creep.moveTo(source);
}
}
}
};
Also added a check for closest source by Range. This'll return the closest source to the creeps current position.
Upvotes: 0
Reputation: 46
I'm pretty sure transferEnergy() doesn't work for the controller, here's the code I found works for simple automation of the upgrade process.
if(creep.carry.energy < creep.carryCapacity) {
var sources = creep.room.find(FIND_SOURCES);
creep.moveTo(sources[0]);
creep.harvest(sources[0]);
}
else {
creep.moveTo(creep.room.controller);
creep.upgradeController(creep.room.controller)
}
Upvotes: 3