Navigation

    forum

    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    1. Home
    2. flareboy127
    • Flag Profile
    • block_user
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Groups
    • Blog

    flareboy127

    @flareboy127

    1
    Posts
    773
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    flareboy127 Follow

    Posts made by flareboy127

    • Need help with Repair Creep Code

      I'm trying to make a basic creep that will go and repair very damaged buildings around my base, but the creep seems to do nothing even though I'm getting no errors.

      My code for the repair creep:

      var roleRepairer = {
       
          /** @param {Creep} creep **/
          run: function(creep) {

              if(creep.memory.reparing && creep.carry.energy == 0) {
                  creep.memory.repairing = false;
              }
              if(!creep.memory.repairing && creep.carry.energy == creep.carryCapacity) {
                  creep.memory.repairing = true;
              }

              if(creep.memory.repairing) {
                  var targets = creep.room.find(FIND_STRUCTURES, {
                   filter: object => object.hits < (object.hitsMax/4)
                  });

                  targets.sort((a,b) => a.hits - b.hits);

                  if(targets.length > 0) {
                      if(creep.repair(targets[0]) == ERR_NOT_IN_RANGE) {
                  creep.moveTo(targets[0]);    
          }
      }
              } else {
                  var sources = creep.room.find(FIND_SOURCES);
                  if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
                      creep.moveTo(sources[0]);
                  }
              }
          }
      };
      module.exports = roleRepairer;

       

      And in the main module i call

      var roleRepairer = require('role.repairer');

      and then run the role with

      if(creep.memory.role == 'repairer') {
                  roleRepairer.run(creep);
              }

       

      posted in Help
      flareboy127