Navigation

    forum

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

    Excellion

    @Excellion

    3
    Posts
    844
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    Excellion Follow

    Posts made by Excellion

    • RE: Calling a second function from a function.

      Thank you both for the valuable hints!

      The "class pattern" comment made me realize that a function within a function actually works like a class, and after realizing that several googled code snippets started making sense. The mention of "this." being able to access objects within that class solved the rest of the puzzle for me.

      If someone would happen to stumble upon this question: The code below is a rewritten version of my simplified code above, this time in working order. 

      -- main.js --
      var Logdata = require('trial')('This is the input data');

      module.exports.loop = function () {
      Logdata.logvalue()
      }

      -- trial.js --
      var classStructure = function(input){
           return {
                savedinput: input,

                logvalue: function()
                     {
                          console.log(this.savedinput)
                     }
           };
      };

      module.exports = classStructure

      It is also possible to add new function in the "Return" statement within trial.js. That function could then call this.logvalue to invoke the logvalue function.

      posted in Help
      Excellion
    • RE: Edge walls are considered plains, at least in simulation mode

      Since i ran into the same issue:

      Running Game.map.getTerrainAt(0,0,'sim') : Result is wall
      Running Game.map.getTerrainAt(1,0,'sim') : Result is plain

      Except for the walls ar the edges all wall tiles are considered plains. It can be worked around by using the "Customize" menu to place edge walls manually. After this has been done the terrain functions as intended.

      posted in Technical Issues and Bugs
      Excellion
    • Calling a second function from a function.

      Let me start of by saying that before playing screeps i never wrote a single line of code in Javascript - i can write basic code in several other languages but i am quite a novice at most of those. Most issues i run into i can google my way out of but with one issue i seem to have run into a wall.

      What i effectively want to do is call a second function from a main function. The below two scripts are a simplified example of what i am trying to achieve:

      -- main.js --
      var trial = require('trial');

      module.exports.loop = function () {
         trial.outer();
      }

      -- trial.js --
      module.exports =
      {
          outer: function()
          {
             inner('ValueToPassOn')
          },
          
          inner: function(value)
          {
              console.log(value)
          }
      }

      What i hoped to achieve was calling trial.outer() in the main function, with the result being that it would call "inner()" and write some test data to the console. In the actual function the "outer" function has to do a variable number of calls to "inner" with different parameters.

      I can think of multiple ways to work around the issue itself; I could create a new "trial.sub.js" which would contain the inner function and just include it in the current file for example. That, and all of the other ideas sound like bad coding practice in my mind.

      What am i missing here? Is there any way to call a function in trial.js using a function in trial.js? Thanks in advance for the assist here!

      posted in Help
      Excellion