Reputation: 1
The problem mainly is the repairer will only fix a few pieces of wall, like one or two pieces. So, it don't make it work. If you have better ideas to add to the code or to fix it. Please write in the comment or answer what tou fix or add. Thank you very much. (My first time play Screeps and use stackoverflow
This my code:
var roleRepairer = {
run: function(creep)
{
if(creep.memory.repairing && creep.store[RESOURCE_ENERGY] == 0) {
creep.memory.repairing = false;
creep.say('🔄 harvest');
}
if(!creep.memory.repairing && creep.store.getFreeCapacity() == 0) {
creep.memory.repairing= true;
creep.say('🚧 repair');
}
if(!creep.memory.repairing && creep.carry.energy == creep.carryCapacity)
{
creep.say('repairing');
creep.memory.repairing = true;
}
if(creep.memory.repairing)
{
var potentialRepairSite = creep.room.find(FIND_STRUCTURES, {filter: (structure) => {return (structure.structureType == STRUCTURE_ROAD || structure.structureType == STRUCTURE_RAMPART || structure.structureType == STRUCTURE_WALL)}});
for(i = 0; i < potentialRepairSite.length; i++)
{
if(creep.repair(potentialRepairSite[i]) == ERR_NOT_IN_RANGE)
{
creep.moveTo(potentialRepairSite[i], {visualizePathStyle: {stroke: '#ffaa00'}});
}
}
}
else
{
var sources = creep.room.find(FIND_SOURCES);
if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
creep.moveTo(sources[0], {visualizePathStyle: {stroke: '#ffaa00'}});
}
}
}
};
module.exports = roleRepairer;
Please help me fix it out, thank you.
Upvotes: 0
Views: 108