Navigation

    forum

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

    _Nlight_

    @_Nlight_

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

    _Nlight_ Follow

    Posts made by _Nlight_

    • RE: [solved] How to find containers ? - when assign and concat don't mix

      Well,

       

      I just got out of bed, so I can't tell you why exactly I used Object.assign beside that I remember observing on objects returned byt the game, that their type were not nececarily basic type[*], thus leaving some method calls with 'undefined is not a function'... that is when its returned value is assigned to a variable, otherwise, no error raised, and hell that is an unwelcomed change from Python or C#. Anyway, now I remember why I used it : I just didn't remebember if the returned object of creep.room.find were a real Array, I still have to remember how to test the type of an array, instead of 'typeof []', whom return value is not helpful [Object object] or something...

       

      By the way, here is the code right now - will be slightly modified to handle cases where there is no containers - with the preceding section, you will notice that I also used Object.assign with no problems whatsoever in the first part:

      let buildings = Object.assign([],creep.room.find(FIND_MY_STRUCTURES, {
      filter: function(structure){
      return (structure.structureType == STRUCTURE_EXTENSION || structure.structureType == STRUCTURE_SPAWN);
      }}));
      assert(buildings.length > 0, 'spawns and extensions not detected in hauler AI');
      let lenBuildings = buildings.length;
      let tmp = creep.room.find(
      FIND_STRUCTURES,
      {filter: (s) => s.structureType == STRUCTURE_CONTAINER}
      );
      assert(tmp[0].structureType == STRUCTURE_CONTAINER);
      buildings = buildings.concat(tmp);
      // buildings are filled first with spawns and extensions and only then containers are added to it.
      // so iterating over buildings, the first buildings will be spawns and extensions.
      assert(buildings.length > lenBuildings, 'container not detected in hauler AI');
      assert(buildings[lenBuildings].structureType == STRUCTURE_CONTAINER);

       

      [*]:but maybe these observations were just the fruits of tireness...

      posted in Help
      _Nlight_
    • RE: [solved] How to find containers ? - when assign and concat don't mix

      Nah, forget it : apparently concat() and Object.assign() don't mix very well... I really don't know why, but it did. That is... a bit depressing though when things that should work don't ...

      anyway... hope it can be of use to someone.

      posted in Help
      _Nlight_
    • [solved] How to find containers ? - when assign and concat don't mix

      Hi all,

      I have the same problem as the author of this post :

      http://screeps.com/forum/topic/945/CONTAINER-not-found 

      However, I have already written it correctly (well, obvioulsy not in fact), yet it does not work :

      buildings.concat(
      Object.assign(
      [],
      creep.room.find(
      FIND_STRUCTURES,
      {filter : (s) => {return s.structureType == STRUCTURE_CONTAINER}}
      )
      )
      );
      // buildings are filled first with spawns and extensions and only then containers are added to it.
      // so iterating over buildings, the first buildings will be spawns and extensions.
      assert(buildings.length == 7, 'container not detected in hauler AI');

      what is wrong with it ?

      Could someone explain to me the subtleties of thes evasive unowned structures ?

      posted in Help
      _Nlight_
    • RE: [solved][JS] how to modify the property accessing mechanics of an object

      Ahhhhhhh.... okay, now that makes sense... yup, confusing it was indeed. 🙂

      posted in Help
      _Nlight_
    • RE: [solved][JS] how to modify the property accessing mechanics of an object

      Really ? Just like that ?

      I feel so dumb...

      I just assumed that because objects stored in Memory were serialized / "stringified" / whatever, objects like arrays and "dictionaries" ( {a:1,...} ) , any property request on Memory would return a duplicate of the value...

      And your statement made me understand that the console  only evaluate expressions (this, kinda sucks)

      Well, that reminds me a lesson : don't overthink things, try & see...

      Thanks pal 🙂

      posted in Help
      _Nlight_
    • [solved][JS] how to modify the property accessing mechanics of an object

      Hi everyone,

      I discorvered Screeps few days ago (and JS with it...), I already know programming metaclasses with python.

      I would like to make an object which is basically a simple alias, the goal is to work with Memory.

      let says that we set this :

      Memory.myGlobals = {};

      Let's imagine that I create the object that act as an alias (as in C), and name its instance '_glob'

      in the end, typing this :

      _glob.stuff = 1;

      have to be the same as

      Memory.myGlobals.stuff = 1

       

      While in python I would play with a metclass overriding the attribute accessing of the targeted class to re-route any of its attribute request towards Memory.myGlobals, In JS I just can't figure it out !

      I tried to grasp the getters and setters, but it only applies on one property, not just any...

      I made something else, but the way it is used is... well, not as convenient as what I want to acheive.

      In pseudo-code, the core of the idea should give that

      Memory.myGlobals = {};

      function Alias(){
      this.__classAttributGetter__ = function(attributeName){
      return Memory.myGlobals[attributeName];};
      }

      alias = new Alias();
      alias.stuff = [];
      alias.stuff.push(1);

       

      SO, would you know how to do this ?

       

       

      posted in Help
      _Nlight_