Lemme just elaborate a bit on why your test variable gets reset and such: saved games are basically saved
states, including all the variables. When you restore a game, the engine itself clears out everything, unpacks the heap from state to RAM, sets an internal flag, and resets itself to just before it calls your game's
play method. Except it doesn't because the internal flag lets it know to call
replay instead. This is all done by the engine itself, you can't influence that from inside the game.
I've not had any further success finding anything about "RestoreGame." It looks like a procedure, but maybe it's something else? There doesn't seem to be anything like it in any of the Scripts the Game Script uses (or subheaders for that matter).
Kernel procedure, part of the engine.
Edit: I just got an idea on how to make certain variables not reset. What you could try to do is have
Game::restore write the specific globals you want to persist to a file. You do this
right before the
(RestoreGame objectName gameNum gVersion) call. Then in
Game::replay, somewhere at the start, you check for that file's existance, read the values for those same globals back in, and delete the file. That way, if your persistent global was, say, 42 at the time you decide to restore, it'll save that 42 to the temp file, restore the game and reset the global to whatever that savegame says it was at the time (41?), and then immediately see the file and load 42 from it.