@famine Thanks for pointing me in the right direction, I used let. The code is a bit-long winded - I am surprised it worked tbh - but it did
run: function(creep) {
let prospect = new RoomPosition(34,4, 'W57S45');
let home = new RoomPosition(16,34, 'W57S44');
if(creep.memory.prospecting && (!creep.pos.isNearTo(prospect) || creep.carry.energy === creep.carryCapacity)) {
creep.memory.prospecting = false;
creep.say('⛏ seeking');
}
if(!creep.memory.prospecting && (creep.carry.energy < creep.carryCapacity && creep.pos.isNearTo(prospect))) {
creep.memory.prospecting = true;
creep.say('Container');
}
if(creep.memory.prospecting) {
var sources = creep.room.find(FIND_SOURCES);
if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
creep.moveTo(sources[0], {visualizePathStyle: {stroke: '#ffaa00'}});
}
}
if(!creep.memory.prospecting && creep.carry.energy < creep.carryCapacity) {
creep.moveTo(prospect)
}
else if (!creep.memory.prospecting && creep.carry.energy === creep.carryCapacity) {
creep.moveTo(home);
var targets = creep.pos.findClosestByPath(FIND_STRUCTURES, {
filter: (s) => (s.structureType == STRUCTURE_CONTAINER || s.structureType == STRUCTURE_STORAGE) &&
s.store.energy < s.storeCapacity
});
if(targets) {
if(creep.transfer(targets, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.moveTo(targets, {visualizePathStyle: {stroke: '#ffffff'}});
}
}
}