Save File Failsafes

Every user of RM's from XP to Ace has learned that a lot of scripts break old savefiles when added.


That is basically because they expect their data to be available ingame, but that data is created by "new game" and older savefile doesn't contain it.


That is why there is a rule "if you added a new script, start a new game" in most descriptions and tutorials.


However, there are ways to circumvent that problem - it basically only exists because a lot of scripters never cared to build in a failsafe against that problem.


I suggest we take the preparation for MV and the switch to javascript as an opportunity to make such failsafes a community-standard.


It will help improve the way the scripts and plugins work and make the games a lot more stable.


Such a failsafe just means that the load-function for the savefiles needs to check if the required data is included in the savefile and if not call the same function as the new game to create that data at a later time.


That is not as easy as it sounds at first (which is why a lot of beginner scripter didn't do that in the past), but if the script community plans for it and provides templates from the beginning, then all scripters could easily copy these functions into their own scripts (or use them in some form of core script).


The same principle could also be used in battlescripts - most errors from summoning or actor change scripts in non-default battlescripts happen because the new actor is missing battlesetup-data, and if the battlescript simply checks for the data and sets it to default if non-existing, that would also improve compatibility.


The final implementation has to wait until we see how RMMV handles the data, but I think we should prepare such methods - what are your opinions?
Yeah, this is a thing that should happen.

I would with Ruby but I don't know how Lol.

If templates are put up when the scripting system is public, that would help a ton.
Source has made a script that succeeds where my own script failed. As far as I know, this is the only script that does what we're looking for, and it hasn't broken on me yet. It's not a default script at all, and it may take a bit longer to load a save, but in my experience this script works.
Source has made a script that succeeds where my own script failed. As far as I know, this is the only script that does what we're looking for, and it hasn't broken on me yet. It's not a default script at all, and it may take a bit longer to load a save, but in my experience this script works.
But if scripters took these steps in the first place, such a script wouldn't be needed.
But if scripters took these steps in the first place, such a script wouldn't be needed.
True, and I'm not saying we shouldn't, but for Ace at least, since it's far too late to fix that now, we have something to help with the problem.
yes, it can't be fixed with the thousands of scripts available for Ace - but we can prevent that problem with RMMV, especially if someone translates it and gets the other communities (especially Japan) onboard with this as well.
Unless you load a save that prompts it do a command via eval upon load, errors won't happen. *rolls away*
I always have old savefiles in mind when I make my scripts, but I don't have much hope that everybody will start doing the same. There are many scripters that don't even come to this forum.

Would be nice if we could have a plugin directory with some kind of rating or tag system, so that we could mark plugins that have this (or other) kind of problem.
Good news are:

Javascript does not treat objects as ruby does. And by that I mean, there are no serialization (the closest thing is converting to json or.. mongoD😎.

And javascript is such a silly language, you MUST do failsaves, a lot, for everything, even your own code, belive me, checking where null is in the code is a pain in javascript, even more than ruby or other languages.

For example:

if you make a method like:

actor.calculateSomething();Don't ever try to figure out if actor.calculateSomething = null, because when you do that, it doesn't show a "method doesn't exists" it shows a "null is not a callable object"

a probably better way to store information on save data without having too much trouble always was to use a variable inside game_system, and in the getter put something like:

Code:
class Game_System  def options    return @options ||= Game_Options.new  endend
Although I think such failsafes should be strived for in most cases, there might be some edge cases making making this as a community standard quite challenging. For instance:

Spoiler
Edge case 1 -

Let's say a script uses an array to store some data in version a. The element orderings inside the array's irrelevant.

At version b, the scripter decided to make the element orderings inside the array to become relevant for whatever situations and reasons, and users can now setup those orderings.

At the time version b was the latest version, if an user switched from version a to version b, I'd like to know how the scripters can handle the element orderings(both using the old one and overwriting it with the new one can lead to undesirable results respectively, as the former can lead to unintended orderings and the latter can overwrite important states in the old saves), besides giving tools to users to let them change that themselves, with appropriate teaching from the scripters, thus requiring the users to be trained.

Edge case 2 -

Let's say a script has a notetag, storing RGSS3 codes written by users, for a data type stored under Whatever_Data.

At version a, the script stores those RGSS3 codes as simple strings, which is used by instances under Whatever_Class via direct eval, in data having that notetag. Those RGSS3 codes are designed to include methods and variables only available under Whatever_Class:

User_RGSS3_Code_1 = "@whatever_variable" # Setting notetag values
Code:
@notetag = "User_RGSS3_Codes" # Storing notetag values
Code:
eval(data.notetag) # Using notetag values
At version b, the scripter decided to use lambda with eval but without instance_exec to store those RGSS3 codes, and use call to use them instead, for whatever situations and reasons. As those lambdas are initialized under Whatever_Data while they're designed to include methods and variables only available under Whatever_Class, all those has to be referenced by those Whatever_Class instances passed to be lambdas, meaning accessors are needed for each instance variable under Whatever_Class and all those RGSS3 codes have to be rewritten to reference methods and variables only available under Whatever_Class:

Spoiler
User_RGSS3_Code_1 = "instance.whatever_variable" # Setting notetag values
Code:
@notetag = eval("-> instance { #{"User_RGSS3_Codes"} }") # Storing notetag values
Code:
data.call(self) # Using notetag values
At version c, the scripter decided to use lambdas with instance_exec as well for whatever situations and reasons. Now using methods and variables only available under Whatever_Class no longer needs to be referenced by its instances passed to be lambdas, so those accessors of its variables solely for them to be used by lambdas are no longer needed and thus deleted:

Spoiler
User_RGSS3_Code_1 = "@whatever_variable" # Setting notetag values
Code:
@notetag = eval("-> instance { instance.instance_exec { #{"User_RGSS3_Codes"} } }") # Storing notetag values
Code:
data.call(self) # Using notetag values
At the time version c was the latest version:

If an user switched from version a to version c, their previously written RGSS3 codes as notetag values wouldn't have to change, but now @notetag has to be changed, albeit easy and simple.

If an user switched from version b to version c, most of their previously written RGSS3 codes as notetag values probably have to be rewritten to get rid of all instance references, and @notetag has to be changed as well. The latter's simple, and the former's a given for users, so right now that's no big deal.

The real issue is, switching from version a to version c and switching from version b to version c needs rather different treatments. In this case that's easy, just uses versioning control practices to detect which old version of the users' switching from, and uses the appropriate treatments accordingly. But when the number of old versions become massive, managing all those cases and corresponding treatments can be really painful.

Another approach is just making each case and corresponding treatment a separate old save file updater, and teaches users which one to choose given their old versions. But then given the massive number of potential users and their types, some of them might just request the scripters to use the aforementioned versioning control approach instead(and sometimes scripters might have to accept even such requests for whatever situations and reasons).

Basically, when a script has major reworking on the existing variables, maintaining failsafes can become tough. Scripters likely have the below choices:

1. Gurantees the scripts are always save file failsafe, and ensuring they'll never have major reworking on the existing variables.

2. States that the scripts are currently save file failsafe, but when the scripts do need major reworking on the existing variables, gives users tools to update them with appropriate teaching. Does this for every old save updating cases.

These issues, while not too difficult, are just for each single alone script . When many scripts, each having many old versions, are designed to be used together in order to work, and some of them of some users' versions are the old ones, I'd be interested in just how many possible cases the scripters and/or users will have to deal with. Although users of all those scripts should keep all of them updated in such cases, it can be wishful thinking in reality 😉

When the save file failsafe issues come up with many scripts, each with many old versions, written by many other scripters, handled by a compatiblity fix script, that compatibility fix script has to be save file failsafe too. God knows how to fix those issues(I suspect that's still can be the case even if all scripts handled by that compatibility fix script are themselves save file failsafes) without driving users insane(I've seen a compatibility fix script handling 26 scripts written by 8 scripters) 😀

Again, I'm not against the save file failsafe practice, I'm actually for it(even though I don't think I'm good enough to achieve save file failsafe yet), I just think making it a community standard is just a bit harsh in general. You might think the aforementioned cases are unrealistic extrremes, but given the massive number of scripts, scripters, user requests, and situations to address, you can seldom be so sure about those. I think it's better to treat save file failsafe for scripts as their temporary(but hardly eternal) bonuses instead(so something like using a flag indicating whether the script's save file fail safe, and/or showing all its old version cases details, can be used) 🙂
As DoubleX notes, there are several general types of cases to consider

1. Introduction of variables

2. Modification of variables

3. Removal of variables

In my Ace scripts, I have typically only provided support for new variables via lazy-loading (as Ramiro shows). Since the variables are created "as needed" you don't have to worry about old save files as much because the game will generate them when it needs them.

Modification of variables gets tricky, since there are so many different ways a single variable could be modified. And it's not even the variable itself that might be an issue: the code might have completely changed the way it handles the variable.

var exp = 512;Suppose you started with 512 EXP as a flat value.But then later you decided you'll treat that variable as a percentage, with 100 being 100%. Now suddenly 512 means...512%? The value of your variable means something completely different, and it would be incorrect to accept save files that assumed it was just a flat value.
Suppose you started with 512 EXP as a flat value.But then later you decided you'll treat that variable as a percentage, with 100 being 100%. Now suddenly 512 means...512%? The value of your variable means something completely different, and it would be incorrect to accept save files that assumed it was just a flat value.
Is there any real-world example of this scenario? I've never had to change anything like that. The times when I actually changed the purpose of a variable, I changed it completely: From number to array, or something like that.

In that case all you need to do is check the type of the value.
Is there any real-world example of this scenario? I've never had to change anything like that. The times when I actually changed the purpose of a variable, I changed it completely: From number to array, or something like that.

In that case all you need to do is check the type of the value.
Have you handled compatibility issues with dozens of scripts written by several scripters(with several being advanced complex scripts) each having dozens of old versions? I'd like to know how the save file failsafe can be maintained without driving users insane(Just don't say such situations won't exist, there's already at least 1 plug and play compatibility fix scripts addressing such level of compatibility issues, and that script's used in a project with 200 scripts written by 30 scripters) 🤣
Is there any real-world example of this scenario? I've never had to change anything like that. The times when I actually changed the purpose of a variable, I changed it completely: From number to array, or something like that.


In that case all you need to do is check the type of the value.
I can't think of any examples off the top of my head where the same variable is given a different purpose, or the way its handled is changed.


I mean, specification changes are possible, but I don't think anyone would actually do that after releasing their game.
Indeed, I have 4 or 5 scripts not written by me on my projects and I know their code as if they were mine, so I don't have that kind of problem. But... if each scripter handles their own scripts properly, what would be the issue?
The problem of specification changes does pose a difficulty (the original idea was only failsafes for new data, not changed data), but I also consider this a rare occurance - especially since the scripter who did those changes is also responsible for the failsafes and could simply provide an output "sorry, old data incompatible" when detecting that instead of forcing a compatibility.


That is also the reason why the problem with dozen different scripts shouldn't appear: all scripters should only check for the data needed by the script they're writing, NOT to solve problems caused by other scripts.


Providing failsafes for other scripters should not become part of this, as it would drive most scripters (especially beginners) insane.


If the failsafes are limited to each script individually, but included in all community scripts (each for themselves only), that should be enough to ensure greater stability.
The problem of specification changes does pose a difficulty (the original idea was only failsafes for new data, not changed data), but I also consider this a rare occurance - especially since the scripter who did those changes is also responsible for the failsafes and could simply provide an output "sorry, old data incompatible" when detecting that instead of forcing a compatibility.

That is also the reason why the problem with dozen different scripts shouldn't appear: all scripters should only check for the data needed by the script they're writing, NOT to solve problems caused by other scripts.

Providing failsafes for other scripters should not become part of this, as it would drive most scripters (especially beginners) insane.

If the failsafes are limited to each script individually, but included in all community scripts (each for themselves only), that should be enough to ensure greater stability.
So compatibility fix scripts can be exempted from the would-be "save file failsafe community standard" right?

Also, I think I've to make my points more crystal clear:

1. I think scripters should always try their best to make their scripts as save file failsafe as possible without compromising anything else too much, but I'm rather skeptical about the thinking of "scripters should always make their scripts failsafe", until it's proven that it's always possible to always ensure 100% save file failsafe, and without compromising anything else too much. The burden of proof lies on those proposing the community standard in this case.

Instead, I think save file failsafe should be treated as an optional yet massive bonuses to scripts that are always strongly encouraged by the community, but not a given from them, as I highly doubt if making save file failsafe a community standard will even work.

If the demand of save file failsafe from the community is that huge, it'll speak for itself. Scripts having a save file failsafe guarantee will be generally preferred over those don't, and most user-oriented scripters will try to adapt if they can. I just don't find any real need to treat maintaining save file failsafe as a community standard.

2. If every single alone script's itself save file failsafe, then yes, ensuring save file failsafe for compaitiblity fix scripts as well will be much, much easier(but in really extreme yet real cases it's still painful like hell for the users), but obviously that's just a wishful thinking.

Even if this community itself managed to maintain this community standard, this community isn't the only RM community, and probably won't be the only RMMV community. Also, there will likely be scripting teams and individual scripters that don't join any RMMV community. Unless every single scripter managed to guarantee all their scripts are always 100% save file failsafe, when there are requests asking for compatibility fixes between scripts in this community and those outside it, those compatibility fixes will still likely have to deal with old save problems with scripts outside this community.

3. There are mainly 2 reasons to achieve save file failsafe:

- Some old saves must be reused. In this case, achieving save file failsafe is a must, whether by the scripts themselves or with specific snippets designed for those specific projects.

- Gives users 1 more choice, besides always forcing them to start the new game over. In this case, achieving save file failsafe is to make scripts more user-friendly by making their lives easier, although it's not a must.

For the 1st one, scripters addressing those cases have no choice but to try their best to ensure save file failsafe as much as they can.

For the 2nd one, scripters have to think if always ensuring 100% save file failsafe will actually make the scripts even less user-friendly, as the point here is to increase user-friendliness, but not enforcing the save file failsafe community standard.

As scripters can seldom tell those cases won't come, they'll have to handle both for each script. A better choice than enforcing the community standard is to write scripts that don't guarantee save file failsafe, and make a save file failsafe patch for each of those scripts to guarantee save file failsafe when the patches are used as well.

If the 1st case comes, then use the patchs as well; If the 2nd case comes, then simply don't use the patches. Such flexibility can only be achieved without enforcing the community standard.

4. Just because a situation's rare alone doesn't mean we can simply ignore it, as they're still real user demands after all. This comes down to the fundamental scripting philosophy for scripters and the philosophy of the whole scripting community. If the scripting community is to meet users' demands that can be met by scripts, then it'll need scripters who are user-oriented. To users, 1 major value scripters and scripting communities give them is the tools they offered to help users meet their demands.

Although I won't say scripting communities must always highly prioritize this goal, nor scripters must always be user-oriented, if save file failsafe becomes a community standard, scripters serving this community will have no choice but to guarantee all their scripts are always 100% save file failsafe. Just think about how many scripters can and are willing to maintain this standard, what the impact on the scripting community will be if many scripters failed to do so, and what the impact on the RM community if many scripters quit the scripting community. Even if all scripters managed to maintain this standard, think about those rare users whose demands are ignored by the scripting community.

5. Unfortunately, "If every single alone script guarantee it's always 100% save file failsafe, then no script will have to handle save file failsafe for the other scripts" is also a wishful thinking in projects using hundreds of scripts, each with dozens of old versions, written by dozens of scripters. Try to manage someone else's project lasted over an year, with 200+ scripts written by 30+ scripters for several months, and you'll likely know what I'm talking about.

You can say such cases are rare and those users deserve to suffer from the pains they introduced to themselves in the first place, but then it again comes down to the fundamental philosophy of scripters and the scripting community. Although I won't enforce mine to anyone besides myself, I still want to be user-oriented and help them meet their demands.

6. Achieving save file failsafe from preventing the issues from happening in the first place isn't the only way to solve them. Users can always request scripters to write specific snippets designated for their projects to solve the issues as well. Enforcing the community standard means scripters must solve the issues by preventing from happening in the first place.

If RMMV will have a master script list, I'd propose adding a field called "Save File Failsafe?" showing the scripters' claim for how save file failsafe the scripts are.

In the community script forum, scripters can also be encouraged to add a tag like "Savefile Failsave" to indicate they claim that the scripts are save file failsafe.

But again, the point is to just treat save file failsafe as a massive bonus strongly encouraged by the community, but not a community standard.
but then it again comes down to the fundamental philosophy of scripters and the scripting community.
Seems like what Andar's trying to achieve with this pre-emptive strike on uninitialized data.


If we only focus on the problem of a savefile simply not loading because a new variable was introduced but performs no checks for whether it's initialized, it should be much easier to solve.


Lazy-loading solves the problem and does not require you to perform extra checks when loading a save file.


For situations where lazy-loading is unfeasible, you could just check whether a particular variable is defined or not (undefined? I'm not sure)
Seems like what Andar's trying to achieve with this pre-emptive strike on uninitialized data.

If we only focus on the problem of a savefile simply not loading because a new variable was introduced but performs no checks for whether it's initialized, it should be much easier to solve.

Lazy-loading solves the problem and does not require you to perform extra checks when loading a save file.

For situations where lazy-loading is unfeasible, you could just check whether a particular variable is defined or not (undefined? I'm not sure)
But then we'll have to explain to users knowing nothing about scripting, as they mostly just care if the old saves can be loaded without troubles. Most of them don't understand the difference between uninitialized data and existing ones with major reworkings. They just know if the save file failsafe attempts worked or not.

Do you think it's even remotely realistic to teach most of them about this, give how massive this group is?

Frankly, I'm a bit pessimistic for this one, but just check how many script users posted their requests and bug reports they faced with all the necessary information, despite how much efforts the community has put on teaching them how to post such requests and bug reports that work and encouraging them to do so.

If the community uses a save file failsafe standard, most of them will probably think most scripts in this community will mostly be save file failsafe, as that's likely all they can get from the meaning behind the standard.

But if the so called guarantee only works on uninitialized data but not existing ones with major reworkings, and some of them faced the latter case, what do you think they'll feel/think about the so called guarantee, even if it's clearly explained beforehand by the standard and the scripts? If I were that scripter who is user-oriented, I really don't know how I could make them understand that, let alone addressing their disappointments and dissatisfaction nicely.

Even if users understand that, if they're using compatibility fix scripts addressing many other scripts, scripters will have to list all possible cases, with which only involves uninitialized data, and which involves existing ones with major reworkings. Users will then have to check that massive exhaustive list against their cases, and that process itself can already be quite painful for them. If I were one of them, I'd just ask the scripters to write a specific snippet designated for my cases to meet my demands instead.

Again, some can always say these are rare cases, but to user-oriented scripters, they're still real cases faced by real users, and they'll still want to help those users to meet their demands.

To sum up, while I think strongly encouraging scripters to try their best to guarantee all their scripts are 100% save file failsafe in the case of uninitialized data is excellent, I highly doubt if making it a community standard will indeed do more good than harm to the community, given the current state of the community. I think treating it as a massive bonus instead of given will likely work significantly better.
Do you want us to admit defeat before trying? Are you telling us that we shouldn't try because we cannot get a perfect 100% anyway?


I know that we won't get perfection - there will always be beginner scripters who don't understand what this is about and are simply missing the experience to get their scripts right.


But giving tutorials and guidelines on how to do it right will help everyone, and even if we are left with 40% scripts that aren't failsafe that still is a large improvement above the current situation where 90% or more of the scripts require a new game to work.

Original thread: https://forums.rpgmakerweb.com/threads/save-file-failsafes.43577/