That's correct, yeah, there's not really a straightforward way to persist those types so they just get ignored by the save system. Closures getting trashed by jumps is a little bit awkward, though; I'll see if I can work out a mitigation for that, or at least document it.
Viewing post in save/load behavior around function objects
a related suggestion, i suppose: maybe exclude some globals from being serialized to avoid trashing? from my testing, it seems that story modules get executed on every launch. this makes serializing any globals set in module body pointless (or even harmful/confusing), as they will be overwritten on game start. you could allow the game to set a glob string to filter globals by (flat or recursive). example:
prog = {money = 700, day = 1}
events = {
{ id = "merchant", day = 3, is_available = function() <...> end }
}
--only save children of prog recursively;
-- default glob would be ** for backwards compat
setSaveDataGlob("prog/**")
or a less unixy form that might be easier on the implementor (not sure)
setSaveDataFilter(
{
{ "prog", "persistent", }, --everything in <global>.prog.persistent down recursively
{ "stats", { "lifetime", "thisRun" } }, --everything in <global>.stats.lifetime and <global>.stats.thisRun
{ "settings", "!someStupidHoldover" }, --everything in <global>.settings minus <global>.settings.someStupidHoldover
-- in short: filter is a list, strings are exact matches, nested lists are forks, ends of lists are wildcards, special syntax for negation
} )
this might be overengineered. a plain list of strings + a special default value for “include everything” is realistically enough
Ahh okay I see what you’re doing here now. Yeah, I’m not sure if I want to add globbing machinery but I understand why you’d want to have some global constants that the save system doesn’t touch.
In this example it looks like you’re storing variable/saveable data in prog, and an unchanging list of storylets in events, so would it be enough to have a command just excludes specific identifiers from the save system? (like dontSave("events") or something)
the example differs from my actual material so far. i have been placing “constants”, the statusLine bypass string, lookup tables related to the “constants”, etc in globals. i’ve packed all persistence data into prog/**. it’s a whitelist kind of situation.
a flat filter could be complemented with a whitelist/blacklist toggle, that should cover me and probably anyone who comes after me.
i’ll also note i’m willing to take a swing at implementing the features i request if given source access. they seem to be piling up rather quickly, it’s only fair i contribute back.
Okay, here’s what I’ve got so far:
dontSave()excludes named identifiers from being saved. You can call it with a single string or a table, and you can call it multiple times to add more identifiers to the list.onlySave()does the opposite, excluding everything but the listed identifiers (and has the same signature/usage pattern asdontSave) (also the do-not-save list takes priority if there’s overlap for some reason)
Currently I’d prefer not to make the save filtering more complex than this (for UX/documentation/support reasons, the actual code isn’t a problem) but: I’ve also added a mechanism for extending the engine with an _init.lua file that gets run at startup and has access to all the stuff inside Folia, so if you or anyone else wants to adjust how things work in the core you’ll be free to do that without having to make a custom build or w/e.