-
I need a role and script only to fix my roads I'm new to the game and programming in general. so dont make fun of the code I'm about to post, but what am I doing wrong and how can I make a code just to repair roads only?
var roleRepairer =
{ /** @param {Creep} creep **/ run: function(creep) {
if(creep.memory.repairing && creep.carry.energy == 0) { creep.memory.repairing = false; creep.say(' R: Hrv'); } else if(!creep.memory.repairing && creep.carry.energy < creep.carryCapacity) { creep.memory.repairing = false; creep.say(' R: Hrv'); } else if(!creep.memory.repairing && creep.carry.energy == creep.carryCapacity) { creep.memory.repairing = true; creep.say(' repair'); }
if(creep.memory.repairing) { const targets = creep.room.find(STRUCTURE_ROAD); targets.sort((a,b) => a.hits - b.hits); if(targets.length) { if(creep.repair(targets[0]) == ERR_NOT_IN_RANGE) { creep.moveTo(targets[0], {visualizePathStyle: {stroke: '#ffffff'}}); creep.say('repair'); } } } 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;
and this is posted in my role
repairer and I have var roleRepairer = require('role.repairer'); and for(var name in Game.creeps) { var creep = Game.creeps[name]; if(creep.memory.role == 'repairer') { roleRepairer.run(creep);
included in the main as well thanks in advance for teh help
-
Could you try to fix your post and add a title?
The markup implementation in the forum takes a bit to get used to but it is actually very usable.
Try the tutorial the reference card is missing a lot of details.And make new post so I get a notification when you updated it