Saving Between Sessions, 2021 Edition

So! I want to make my game save between sessions, and I’ve changed the window.storeName in the index.html as specified here: Saving between sessions. However! There appears to be a major issue - if you play the compiled game and refresh, then the next chapter is dropped, and when you reach the chapter transition it tells you to play again/share a game/whatever.

I tracked this down to the SceneNavigator class, which is initialized via parsing the startup file on new games and via mygame.js in cases of refresh. In mygame.js it’s coded as follows by default:

nav = new SceneNavigator(["startup"]);
stats = {};

So, as far as I can understand, it gets the full list on new game start. However if you refresh the page it only gets “startup”, so it runs fine right up until it needs to determine the next scene, then in Scene.prototype.finish it throws its hands up and says that there’s no next scene and you must be done.

Now, I was given to understand by the wiki (Mygame.js | ChoiceScript Wiki | Fandom) that if I’m using the *scene_list command in the startup file, I shouldn’t have to mess with mygame.js, but it looks like I actually should be mirroring my scene order in the JS file, since on refresh never actually goes back and parses out the *scene_list command. I tested this out by editing mygame.js to add my chapters and it appears to have fixed the issue.

So I have two questions.

First, is that all roughly correct?

Second, is there anything else I need to do to make saves work properly? Right now, it’s:

1) change window.storeName to a unique value
2) edit mygame.js to add my scenes to the SceneNavigator
1 Like

Oh wow I didn’t know that you had to change mygame.js to add the scenes (I just had a note telling the player to save, restart, and then load to get past those issues, because that works for some reason). Another thing that breaks when refreshing the page is achievements, which I tried to fix with another hack…

Okay, nevermind the above, I might have just fixed it in my branch of choicescript by adding a hack to save the sceneList and achievements in the save file, which seems to also work?

Saving code: choicescript/util.js at master · aucchen/choicescript · GitHub

Loading code: choicescript/util.js at master · aucchen/choicescript · GitHub

I think your way would work, but achievements might still break it.

1 Like

Oh, interesting! I hadn’t realized that SceneNavigator also held achievement data (my game has none). Yeah, listing the scenes in the javascript file almost certainly wouldn’t fix the achievements issue, but your modification looks like it would fix both.

Luckily I don’t need achievements, but if I ever do it seems like the only option is to do some surgery. Which makes me wonder how CoG handles this - maybe they have a special build process.

1 Like