Page 1 of 1

New function: hackDoNotSave()

Posted: 18 Mar 2017, 14:53
by Per
Add a new, experimental function hackDoNotSave(global name).

It adds global by name to list of variables to not save to savegames. This too is not saved to savegames, so must be called again whenever game is restarted from a savegame.

Re: New function: hackDoNotSave()

Posted: 18 Mar 2017, 17:10
by Prot
Why not just clear useless variables, when event save game is called? Or var's anyway saved but empty?

Re: New function: hackDoNotSave()

Posted: 19 Mar 2017, 13:33
by Per
Prot wrote:Why not just clear useless variables, when event save game is called? Or var's anyway saved but empty?
That should work, too.

Re: New function: hackDoNotSave()

Posted: 19 Mar 2017, 19:15
by NoQ
Prot wrote:Why not just clear useless variables, when event save game is called? Or var's anyway saved but empty?
You'd need to regenerate them when saving is over, not just after loading, which is extra coding. Or you'd want to store them in another variable, which will be saved but under a different name, and then bring them back, which is also extra coding.

It's cool to be able to replace this extra work with a single line:

Code: Select all

var V;
hackDoNotSave('V');
That said, variables in anonymous closures work too, if that's comfortable for your purposes:

Code: Select all

(function(global) {
    var V;
    global.getV = function() { return V; }
    global.setV = function(v) { V = v; }
})(this);
(in this case V would not be saved, but it can escape by reference and live and be accessible for as long as you want)

Per wrote:must be called again whenever game is restarted from a savegame.
If used as in the first code snippet above, i guess it'd work, so it's cool. I was wrong about that in the original proposal.

Re: New function: hackDoNotSave()

Posted: 19 Mar 2017, 22:44
by Per
I'm a bit worried that using tricks like anonymous closures would make the code hard to read and understand, though. One of our primary aims should be to make the code easy to read, understand and improve by anyone who has done some coding before.

Re: New function: hackDoNotSave()

Posted: 20 Mar 2017, 15:28
by NoQ
Yeah. Well, since we started this discussion from hook problems, adding some anonymous closures wouldn't make things much worse. But i agree that letting the scripters stick to simple variables and functions is very beneficial.