Navigation

    forum

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

    GBLightning

    @GBLightning

    6
    Posts
    859
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    GBLightning Follow

    Posts made by GBLightning

    • How does Memory work?

      I've read the https://docs.screeps.com/global-objects.html, but I didn't find the answer...

      I want to save an instance of a class to the Memory. My code is:

      class MyClass {
          constructor(name) {
              this.name = name;
          }
          run() {
              console.log("Run in class")
          }
      }
      let instance = new MyClass('name');
      Memory.classes = {};
      Memory.classes['name'] = instance;
      console.log("'run' method for 'Memory.scripts['name']' (Not in main loop) is:  " + Memory.classes['name'].run)
      module.exports.loop = function () {
          console.log("'run' method for 'Memory.scripts['name']' (In main loop) is:  " + Memory.classes['name'].run)
      }
      

      The console output is:

      [22:40:22]'run' method for 'Memory.scripts['name']' (Not in main loop) is:  run() {
              console.log("Run in class")
          }
      [22:40:22]'run' method for 'Memory.scripts['name']' (In main loop) is:  run() {
              console.log("Run in class")
          }
      [22:40:23]'run' method for 'Memory.scripts['name']' (In main loop) is:  undefined
      [22:40:24]'run' method for 'Memory.scripts['name']' (In main loop) is:  undefined
      [22:40:25]'run' method for 'Memory.scripts['name']' (In main loop) is:  undefined
      [22:40:26]'run' method for 'Memory.scripts['name']' (In main loop) is:  undefined
      

      In the first game tick, the Memory.classes['name'].run is defined. It's a function run().

      But in the following ticks the Memory.classes['name'].run is undefined.

      I would be grateful if someone could help me figure it out.

      posted in Help
      GBLightning
    • RE: Issue with the target for the method creep.reserveController(target).

      @keidence Done! Thank you again!

      posted in Technical Issues and Bugs
      GBLightning
    • RE: Issue with the target for the method creep.reserveController(target).

      I'm stupid 😞 Yesssss! Thank you a lot! That works nice!

      posted in Technical Issues and Bugs
      GBLightning
    • RE: Issue with the target for the method creep.reserveController(target).

      @keidence "Reversing the order of the .reserveController calls?"

      It doesn't affect 😞

      posted in Technical Issues and Bugs
      GBLightning
    • RE: Issue with the target for the method creep.reserveController(target).

      I've added the loop

              let val;
              for(val in controller_X) {
                  console.log(controller_1[val])
              }
      

      after both controllders were defined.

      For the controller_1 that loop returns that:

      [22:03:55][shard3]5bbcaabd9099fc012e6321b9
      [22:03:55][shard3][room W42S38]
      [22:03:55][shard3][room W42S38 pos 18,39]
      [22:03:55][shard3]undefined
      [22:03:55][shard3]function (id) {
              OwnedStructure.call(this, id);
          }
      [22:03:55][shard3]undefined
      [22:03:55][shard3][object Object]
      [22:03:55][shard3]0
      [22:03:55][shard3]undefined
      [22:03:55][shard3]undefined
      [22:03:55][shard3]undefined
      [22:03:55][shard3]undefined
      [22:03:55][shard3]undefined
      [22:03:55][shard3]0
      [22:03:55][shard3]undefined
      [22:03:55][shard3]false
      [22:03:55][shard3]function() {
              var result = {};
              for(var i in this) {
                  if(i[0] == '_' || _.contains(['toJSON','toString'],i)) {
                      continue;
                  }
                  result[i] = this[i];
              }
              return result;
          }
      [22:03:55][shard3]function() {
      
              if(!this.my) {
                  return C.ERR_NOT_OWNER;
              }
      
              intents.set(this.id, 'unclaim', {});
              return C.OK;
          }
      [22:03:55][shard3]function() {
      
              if(!this.my) {
                  return C.ERR_NOT_OWNER;
              }
              if(this.safeModeAvailable <= 0) {
                  return C.ERR_NOT_ENOUGH_RESOURCES;
              }
              if(this.safeModeCooldown || this.upgradeBlocked > 0 ||
                  this.ticksToDowngrade < C.CONTROLLER_DOWNGRADE[this.level]/2 - C.CONTROLLER_DOWNGRADE_SAFEMODE_THRESHOLD) {
                  return C.ERR_TIRED;
              }
              if(_.any(register.structures, i => i.structureType == 'controller' && i.my && i.safeMode)) {
                  return C.ERR_BUSY;
              }
      
              if(lastActivateSafeMode) {
                  intents.remove(lastActivateSafeMode, 'activateSafeMode');
              }
              lastActivateSafeMode = this.id;
      
              intents.set(this.id, 'activateSafeMode', {});
              return C.OK;
          }
      [22:03:55][shard3]undefined
      [22:03:55][shard3]undefined
      [22:03:55][shard3]undefined
      [22:03:55][shard3]undefined
      [22:03:55][shard3]controller
      [22:03:55][shard3]function() {
              return `[structure (${this.structureType}) #${this.id}]`;
          }
      [22:03:55][shard3]function() {
              if(!this.room) {
                  return C.ERR_INVALID_TARGET;
              }
              if(!this.room.controller || !this.room.controller.my) {
                  return C.ERR_NOT_OWNER;
              }
      
              if(this.room.find(C.FIND_HOSTILE_CREEPS).length > 0 ||
                  this.room.find(C.FIND_HOSTILE_POWER_CREEPS).length > 0) {
                  return C.ERR_BUSY;
              }
      
              intents.pushByName('room', 'destroyStructure', {roomName: this.room.name, id: this.id});
              return C.OK;
          }
      [22:03:55][shard3]function(enabled) {
              if(!this.room) {
                  return C.ERR_INVALID_TARGET;
              }
              if(this.my === false || (this.room.controller && this.room.controller.owner && !this.room.controller.my)) {
                  return C.ERR_NOT_OWNER;
              }
              if(!_.isBoolean(enabled)) {
                  return C.ERR_INVALID_ARGS;
              }
      
              if(enabled != data(this.id).notifyWhenAttacked) {
      
                  intents.set(this.id, 'notifyWhenAttacked', {enabled});
              }
      
              return C.OK;
          }
      [22:03:55][shard3]function() {
              if(!this.owner) {
                  return true;
              }
              if(!C.CONTROLLER_STRUCTURES[data(this.id).type]) {
                  return true;
              }
              if(!this.room || !this.room.controller) {
                  return false;
              }
              return utils.checkStructureAgainstController(data(this.id), register.objectsByRoom[data(this.id).room], data(this.room.controller.id));
          }
      

      But for the controller_2 that loop returns that:

      [22:03:23][shard3]undefined
      [22:03:23][shard3]undefined
      [22:03:23][shard3]undefined
      [22:03:23][shard3]undefined
      [22:03:23][shard3]function Array() { [native code] }
      [22:03:23][shard3]undefined
      [22:03:23][shard3]undefined
      [22:03:23][shard3]undefined
      [22:03:23][shard3]undefined
      [22:03:23][shard3]undefined
      [22:03:23][shard3]undefined
      [22:03:23][shard3]undefined
      [22:03:23][shard3]undefined
      [22:03:23][shard3]undefined
      [22:03:23][shard3]undefined
      [22:03:23][shard3]undefined
      [22:03:23][shard3]undefined
      [22:03:23][shard3]undefined
      [22:03:23][shard3]undefined
      [22:03:23][shard3]undefined
      [22:03:23][shard3]undefined
      [22:03:23][shard3]undefined
      [22:03:23][shard3]undefined
      [22:03:23][shard3]undefined
      [22:03:23][shard3]function toString() { [native code] }
      [22:03:23][shard3]undefined
      [22:03:23][shard3]undefined
      [22:03:23][shard3]undefined
      

      Look like that is the reason why method creep.reserveController(target) doesn't work for the second case. Is that an error, or expected behavior?

      posted in Technical Issues and Bugs
      GBLightning
    • Issue with the target for the method creep.reserveController(target).

      Preconditions:

      "shard" is 3.

      "creep" is the my creep that has a body [MOVE, CLAIM, CLAIM].

      "controller" is a neutral controller in the room next to my main room.

      My "creep" isNearTo "controller".

      My code is:

              let controller_1 = Game.getObjectById('5bbcaabd9099fc012e6321b9');
              let controller_2 = creep.room.lookForAt(LOOK_STRUCTURES, flag.pos.x, flag.pos.y)
              console.log("Controller 1 is " + controller_1)
              console.log("Controller 2 is " + controller_2)
              let result_1 = creep.reserveController(controller_1);
              let result_2 = creep.reserveController(controller_2);
              console.log("Result 1 = " + result_1)
              console.log("Result 2 = " + result_2)
      

      Actual output in the console is:

      [21:15:21][shard3]Controller 1 is [structure (controller) #5bbcaabd9099fc012e6321b9]
      [21:15:21][shard3]Controller 2 is [structure (controller) #5bbcaabd9099fc012e6321b9]
      [21:15:21][shard3]Result 1 = 0
      [21:15:21][shard3]Result 2 = -7
      

      But I expect both methods to work. (Or, at least, both methods not to work)

      I don't know what tools you have to reproduce that and I'm not sure how are you supposed to reproduce that... It doesn't reproduced on the [sim] room(

      posted in Technical Issues and Bugs
      GBLightning