main script runs outside of the loop
-
Can anyone explain me why is A called outside of the main loop? It happens periodicaly.
module.exports.loop = function () {
console.log("MAIN START");
Game.test = test;//for console commands like "Game.test()";
console.log("MAIN FINISH");
};
var A = (function(x, y) {
console.log("A START");
var B = function(x, y) {
console.log("B START");
console.log(y);
console.log("B FINISH");
}
console.log("A RETURNS B");
return B;
})();
var test = function() {
console.log("TEST START");
A(1, 2);
return "TEST FINISH";
};/* CONSOLE LOG
-
The "outside of the main loop" script is called when the script is loaded.
This is normal behavior of the game.
When committing code you can actually see this behavior quite clearly, just add a console.log("compile script"); on the top of your script.
The first few ticks it will show "compile script", in later ticks it might show up randomly depending on the server-side cache.
-
Dissi, you mean "outside of the main loop" is loading from time to time on server? not just one time when i compile it with Ctrl+S or something?
-
Everything outside the loop is ran at random intervals when the server loads your code onto a new shard/server:
console.log('run when loaded, at random times, at least once when you commit your script')
module.exports.loop = {
console.log('run every tick ' + Game.time);
}It's the way the server caches your require()'s as well.
-
Thank you, thats all i wanted to know.)
-
The caching appears to happen once every 30 ticks or so. I that helps you in any way.