Navigation

    forum

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

    Posts made by JustMonkeyCode

    • RE: Mysterious error without stack trace

      I've been having strange undefined errors as well.

      First thing I've found out. It appears there have been some changes to the scoping of variables. Before a variable instantiated like myVar = "test", without a var was globally visible. This no longer seems to be true, but on the up side we now can say global.myVar = "test" and have it work fine everywhere except from the console. This is due the second change I've noticed today.

      The console now seems to happen before the main script (and so before anything we write is defined) instead of after as it had be doing. I'm also seeing some console statements being issued multiple times at random intervals after being entered. It does not seem to happen for a console.log issued at the console but when I started getting strange behavior, I added the following code at the very start of my main module:

      console.log('--')
      if(global.test) console.log('from console', global.test);
      

      From the console, issuing test = "a test" just once results in the conditional being triggered once on the very next tick and then around a half dozen more times on random ticks latter. I was still collecting information when I saw your post.

      posted in Technical Issues and Bugs
      JustMonkeyCode
    • RE: Is there any way to execute some function from console?

      The scoping I posted about earlier no longer functions. sigh Time for a major rewrite of all my code.

      posted in Help
      JustMonkeyCode
    • RE: Add the node "global" object to the environment. so that methods declared on it become global to all modules

      While my post was true at the time I posted it, this no longer works, which is not awesome. I was using that fact to expose my constructors globally.

      posted in Feature Requests
      JustMonkeyCode
    • RE: Is there any way to execute some function from console?

      To expand a bit on TheNumberOne's answer, if you defined your function like

      func = function () {dosomethin}
      

      it will be accessible globally (which includes the console). This removes the need to require anything on the console. Note the lack of var, this is important. Both var func and function func limit the scope. If you want it to all hang out, don't dress it up 🙂

      posted in Help
      JustMonkeyCode
    • Unable to expand some watch entries of the `Memory` tab in a windowed editor

      When the code editor is in a separate window, clicking the Memory root entry on the Memory tab has no effect. Other watch paths may or may not expand seemingly at random. Occasionally when another watch path fails to expand, it will acquire a striped animated background which remains until windowed editor is closed.

      None of these issues occur in the docked version of the editor.

      posted in Technical Issues and Bugs
      JustMonkeyCode
    • The ability to preview forum responses before posting and edit after posting

      This forum is naturally going to discuss a lot of code and other technical ideas. Markdown is valuable in helping to communicate clearly, but a poorly placed type-o can render the post difficult to read. Right now the only way to correct a mistake, AFAK, is to delete the offending post and create a new one, but this leads to noise in the inboxes of anyone following the thread.

      posted in Feature Requests
      JustMonkeyCode
    • RE: Add the node "global" object to the environment. so that methods declared on it become global to all modules

      I don't know if this will help you, but objects created without var are visible globally.

      myModule:

      myGlobalVar = "immaglobal";
      var myLocalVar = "immalocal";
      

      myOtherModule:

      console.log(myGlobal); // "immaglobal"
      console.log(myLocal); // error, undefined
      

      main:

      require('myModule');
      require('myOtherModule');
      console.log(myGlobal); // > "immaglobal"
      console.log(myLocal); // > error, undefined
      
      posted in Feature Requests
      JustMonkeyCode
    • API access to Player 2

      In response to a little mishap involving the sim room (I lost all my code), I've written a local script to post my code using the user API and I was wondering if it were possable to access the sim room Player 2 via that same API.

      posted in Help
      JustMonkeyCode
    • RE: Switching between players in sim room may result in loss of code

      Thanks chris, glad to know they respond. I'm not going to take advantage of that this time around. I think I can do a better job starting over and this time I'll be working locally using their API to post code, but just for future reference (and for other's who may run into the same issue), where did you post that rollback request?

      posted in Technical Issues and Bugs
      JustMonkeyCode
    • Switching between players in sim room may result in loss of code

      To test a few lines of code in isolation, I switched to Player 2 then replaced all of my live code with the few lines in question. I have done this previously successfully. When finished, I switched back to my account's Player. My code was not restored. Both players now possessed only the few lines that I had been testing.

      posted in Technical Issues and Bugs
      JustMonkeyCode
    • RE: Get number of creeps with "x" role

      Sorry for the misleading post. Your right, it didn't relate to your issue (as far as I can tell). I copied your code into the sim room and just had to tweak a few things to get it to work. Here is the result:

      require("lodash")
      var harvesters = _(Game.creeps).filter( { memory: { role: 'harvester' } } ).size();
      if (harvesters < 5){
          Game.spawns.Spawn1.createCreep([MOVE], null, {role: "harvester", set: "extractor"})
      };
      

      As long as you have a Spawn1, it'll create 5 creeps then stop. The key change { role: 'x' } to { role: 'harvester' }

      posted in Help
      JustMonkeyCode
    • RE: Get number of creeps with "x" role

      The Game.creeps.myCreep object and the Memory.creeps.myCreep object are two different objects, NOT a reference to the same object. After a createCreep call, these two objects (from what I've seen) become exposed to our code add different times. This subtle timing difference has caught me a few times. Check out my response to this post for a more detailed look at the timings I've observed.

      posted in Help
      JustMonkeyCode
    • RE: How to post code snippets?

      Thanks @avdg_ your post clued me in. I was only using the back ticks and so getting a generic code post. Adding the language qualifier solved the problem.

      posted in Help
      JustMonkeyCode
    • RE: How to post code snippets?
      console.log('This is a test');
      
      posted in Help
      JustMonkeyCode
    • How to post code snippets?

      The Markdown docs say to use triple back ticks. This does work, but the code
      looks
      like
      this

      Other posts have the code on a solid blue background with out gaps between the lines. How is this done?

      posted in Help
      JustMonkeyCode
    • RE: Get number of creeps with "x" role

      Using native JS can be:

      var count = Object.keys(Game.creeps).reduce(function(p, c, i, a) {return p + (Game.creeps[c].memory.role == "aRole" ? 1 : 0)}, 0)
      

      Check out the reduce function.

      posted in Help
      JustMonkeyCode
    • .say() all the things!

      Creep.say is a nice feature that should be included for all in game objects (Spawn, Source, ConstructionSite). Just for kicks, I tried:

      Creep.prototype.say.call(Game.spawns.Spawn1, "test");

      and got back a OK return, but the speech bubble just didn't appear... sigh.

      posted in Feature Requests
      JustMonkeyCode
    • console.clear()

      Debugging can sometimes be a very cluttered affair. Being able to wipe the slate clean is nice.

      posted in Feature Requests
      JustMonkeyCode
    • RE: Small snippet to clear the memory of dead creeps.

      I'm using something like the OP's snippet as part of a garbage collector, but wanted to share part of my learning curve. When using createCreep with a memory argument, that creeps memory created and available to code for the remainder of that tick. The creep itself isn't available until the start of the next tick.

      My first pass had an OP style GC at the end of my code, and I couldn't figure out why my creeps memory were being wipe before the creep was even being created. What was happening was:

      1. This tick:
        1. createCreep called with memory argument
        2. Memory.creeps.myNewCreep available
        3. GC runs seeing Memory.creep.myNewCreep but not Game.creep.myNewCreep so deletes Memory.creep.myNewCreep
      2. Next tick:
        1. Game.creep.myNewCreep has no memory.

      Moving the GC earlier in the tick solved the problem.

      1. This tick
        1. run GC, myNewCreep hasen't been created yet, so isn't deleted
        2. createCreep
        3. Memory.creep.myNewCreep available
      2. Next tick
        1. Now when GC runs both Memory and Game versions of myNewCreep are available, so it is not deleted from memory.

      TL;DR: If you use this snippet, use it very early in your code.

      posted in General Discussion
      JustMonkeyCode