New function: hackDoNotSave()

For AI and campaign script related discussions and questions

New function: hackDoNotSave()

Postby Per » 18 Mar 2017, 14:53

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.
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
 
Posts: 3649
Joined: 03 Aug 2006, 19:39

Re: New function: hackDoNotSave()

Postby Prot » 18 Mar 2017, 17:10

Why not just clear useless variables, when event save game is called? Or var's anyway saved but empty?
User avatar
Prot
Trained
Trained
 
Posts: 65
Joined: 29 Nov 2010, 12:41

Re: New function: hackDoNotSave()

Postby Per » 19 Mar 2017, 13:33

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.
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
 
Posts: 3649
Joined: 03 Aug 2006, 19:39

Re: New function: hackDoNotSave()

Postby NoQ » 19 Mar 2017, 19:15

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.
Last edited by NoQ on 20 Mar 2017, 15:59, edited 2 times in total.
User avatar
NoQ
Special
Special
 
Posts: 6098
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: New function: hackDoNotSave()

Postby Per » 19 Mar 2017, 22:44

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.
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
 
Posts: 3649
Joined: 03 Aug 2006, 19:39

Re: New function: hackDoNotSave()

Postby NoQ » 20 Mar 2017, 15:28

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.
User avatar
NoQ
Special
Special
 
Posts: 6098
Joined: 24 Dec 2009, 11:35
Location: /var/zone


Return to Scripting

cron