Data presists between ticks?
-
The way I understood it data is not supposed to presist between ticks, but it seems to do just that for a short amount of time.
Example code:let debug = {
counter: 0,
run () {
console.log(debug.counter);
debug.counter++;
},
};module.exports = debug;
Running debug.run() in the main loop gives me 0, then 1, then 2, then 3 and so on.
Why is this happening?
-
Data is typically reset on a server node change. Until that change occurs, whatever you have in global space will persist. Some people use this to make up a form of caching, though its usability is in doubt. When a node change occurs is most often unknown, so it's not wise to keep data you can't regenerate in global space since you will have no warning when it disappears.
-
Relevant documentation - http://support.screeps.com/hc/en-us/articles/204825672-New-main-loop-architecture