Creating my own global functions



  • So, say I have a module called "test" that look like

    module.exports = function()
     {
         this.name = "awesome";
     }
    

    When I try to access store that module in a global from the command line, like

    Memory.myTest = require("test");
    Memory.myTest.name
    

    It tells me that Memory.myTest is undefined, even when the first line spits back out the right code. Is there a way to make this work?

    As an alternative, is there a different way to construct my own global functions that can be used from both the code and the command line?

    Thanks!



  • global.foo = function() {
        console.log('test');
    }
    
    // Somewhere else in the code
    foo();
    

    Also, I use my code to check for run functions in the global scope, take a look here to see how I've implemented it:
    https://github.com/avdg/screeps/blob/04f55ec991bad17772bee6a93b7615f8d731c6cb/scripts/main.js#L31

    I simply set a function that sets the global run in the console and it should simply work