Hi, so I have a funny situation that Reddit helped me debug.
I read about the "global object wipe" thing that happens every tick.
any changes in these properties, appearing of new objects, and dismantling of old ones will happen only at the start of the next tick
That makes sense, and is something I have been keeping in mind. But my bug was different, and came about from the following situation:
// main.js
var spawn = Game.spawns.MySpawn;
module.exports = function() {
// ...
if (spawn.spawning) {
// do nothing this tick
}
// ...
};
As you can see, var spawn
is generated at compile time, which I thought would be more efficient. My code worked perfectly during the day, from morning til midnight. But overnight, my code would stop working. spawn.spawning
would be stuck returning whatever it was returning at some point when I wasn't looking. If I changed any line of any file, it would start working, because main.js
would get recompiled!
I believe that overnight, the Game
object is recreated, such that Game.spawns.mySpawn
is a new object. This means that var spawn
is still pointing to the old object, which never gets updated, breaking my colony.
The fix was to do this:
module.exports = function() {
var spawn = Game.spawns.MySpawn;
// ...
};
It took a post on Reddit to debug this because I had no idea that the Game.spawns
object would be repopulated with new data at some point overnight. I don't think this is documented, and if it is, I have still not read that document - and since it was the first line of code I wrote after the tutorial, I think it should be put early in the documentation.