HTML Updating missing variables in old saves

LaughingFoxGames

Member
Game Developer
Dec 4, 2018
132
205
I’m not sure if anyone experience this issue. So what happens is that whenever I add something in the StoryInit passage, like a variable. It does not update with a previous save. So whenever I add that variable and save and then run the game. The variable does not appear, but all the other previous variable are there. Can any one help me with this. This has turned into a major issue for me.
 

Feyschek

Well-Known Member
Game Developer
Jun 12, 2021
1,179
656
I’m not sure if anyone experience this issue. So what happens is that whenever I add something in the StoryInit passage, like a variable. It does not update with a previous save. So whenever I add that variable and save and then run the game. The variable does not appear, but all the other previous variable are there. Can any one help me with this. This has turned into a major issue for me.
There are no easy ways here, but here are my personal examples that I use. Well, I will propose a naked pregnant system.

We create special passages for launching new variables.

That's about how I do it.
<<button 'Ехать к себе домой' `either('Встреча с матерью')`>><<set $Isabellaevents to 1>><</button>>
After clicking the button, the game starts taking into account a new variable in the story, you don't have to write it in the StoryInit pass.

The best way to implement this feature is to make an event that will give the player access to this variable for future events in the game. For me, this was the easiest way to implement a system of new variables and make my old saves work.

Of course, there are more complex ways like writing scripts for javascript, but that's not my thing.
 

guest1492

Member
Apr 28, 2018
316
265
When you save, the current state of the game (including all variables) are saved. When you file, the current state of the game (including all variables) are replaced by what is in the save file. That means it doesn't matter what variables you add to , it will only affect new games and not saved games.

The proper way to update variables inside of saves is to use JavaScript and set a value for along with writing an function.

JavaScript:
Save.onLoad.add(function (save) {
    /* exit the function early if the save is already up to date */
    if (save.version === Config.saves.version) return;
    /* assign 0 to save.version if it is not defined */
    save.version ??= 0;
    for (const moment of save.state.history) {
        const sv = moment.variables;
        if (save.version < 1) {
            /* update variables to align with version 1 */
            sv.someVarAddedInVersion1 = 'some value';
        }
        if (save.version < 2) {
            /* update variables to align with version 2 */
            sv.someVarAddedInVersion1 = 'new value';
        }
        if (save.version < 3) {
            /* update variables to align with version 3 */
            sv.someVarAddedInVersion3 = 15;
        }
        /* etc */
    }
    /* if you want to change save.version, do so here */
    save.version = Config.saves.version;
});
 
  • Like
Reactions: osanaiko