ChoiceScript Saving Plugin (Update: April 2023)

ChoiceScript Save Plugin 2019

Hi all, I spent this weekend completely revamping the current state of the save plugins.
For those new to this, or simply eager to get saves up and running, you can jump straight in by following the link below:

For those who’ve been around a while, or are interested in some history (and/or technical details), please read on. As many people have been saying for a while now, the save plugin situation had become something of a nightmare. With multiple scripts, broken links and scattered (and lacking) documentation all playing a big part. It was proving very difficult for old and new members alike to trundle through this thread finding out which links worked, which files they needed, and how to then use the various features of each script.

I’ve spent the weekend completely tearing apart the two “current” scripts: smPlugin.js and smPluginMenuAddon.js, and combining the majority of their behaviour into one script: ChoiceScriptSavePlugin.js.

I also rewrote the vast majority of the code, making it more reliant on CoG’s own save system (which amusingly Dan also flagged up this weekend). The benefits are still the same though. Unlike just simply enabling the above persistent storage, the plugin allows for you (or the player) to manage a number of save “slots” and provides both new commands and a “quick save menu” through which to do it.

But to cut a long story short: The end result should be something a lot more stable, intuitive and easier to maintain. I’ve also completely re-wrote a detailed configuration and usage guide (with pictures!), which you can view at the link above.

This is now the ‘default’ recommendation, and I won’t actively support save.js, smPlugin.js or smPluginMenuAddon.js (even just typing that out makes me realize how bloated and confusing that must have been!) from here on out.

I hope these changes prove helpful and for the better, but please let me know if you can think of any further improvements.

Many thanks,

CJW

Old Post (pre:sept 2019)

Save.js is deprecated, please see smPlugin.js instead.

For the more advanced (but more complicated) save-framework code, see this post
and download here: smPlugin.js

Or perhaps you’re looking for something that allows players to save ‘on the fly’ (like save.js) but with multiple slots? Try the smPluginMenuAddon.js

[spoiler]For as long as I’ve been here, saving games as been a huge problem and a save system has been on almost every developer’s wishlist.

I’m pleased to say, after a lot of thinking, a few epiphanies and some solid advice from @Vendetta - I’ve come up with a simple, and most importantly transferable solution!

What is it?
This is an automatic save system that acts like games hosted on the official CoG site (autosaves every page).

How does it work?
It uses the native password generating functions to create and store a password in your browser’s localStorage.
The load function then grabs this data and loads/processes a password page automatically in order to restore your game.
Whilst far from being the most glorious method, it seems to work well enough - and for testing purposes that’s all we really need.

The saving is automatic, but you can delete/clear your save and load via the included buttons:

How do I install it?
Because I thought this would be so useful to absolutely anyone creating a choicescript game on the forum I tried to make the inclusion of this mod as simple as is humanly possible (hence some of the limitations, like being single-slotted and automatic).

To install:

  • Download this file (right click and ‘save as’).
  • Put that file in your ‘webs’ folder (the one with ui.js and scene.js in it)

  • Open index.html and include the file as a script ( It MUST come after ui.js and scene.js):

  • Now all you need to do is open save.js and change the value of the variable at the top called “mygame_save”, to ensure your instance of the save system is unique to your game. Don’t keep changing this value however, as it’ll break your player’s saves.

How do I uninstall it?
Un-include the script file.

Things of Note

  • Only the latest versions of browsers support localStorage (IE8+) Chrome, Firefox etc.
  • This is only a one-slot save automatic save system, but it WILL retain information after you close your browser.
  • This mod overwrites some native interpreter functions so if you’ve made heavy edits to scene.js and ui.js - This mod may cause problems.

There’s a demo here if you have any doubts, simply load up the game play to a certain point - quit - load it back up and hit ‘load’ - you should return to exactly where you left off:

https://dl.dropboxusercontent.com/u/7840892/CJW/choicescript/code/autosave-plugin/index.html


I’ve wanted to deliver this to y’all for a while now, and I’m really excited to finally be able to.
This system isn’t perfect, I know - but hopefully it’s a good start to fixing a common gripe and I hope it makes everyone’s cs deving that little bit easier, until something better comes along!

I hope it helps.

Merry Christmas EveryChoiceScripter! :)[/spoiler]

66 Likes

awsome!!! u rule

@CJW

Thanks for this, I’ve added it to my game :slight_smile:

i think u should give credit to cjw for doing this for us i will put his name in my game

1 Like

@irule9344

Good point! I’ll add the credit!

Might want to redownload (or uncomment updateSave()), just realized I commented out the wrong function… -.-’
And don’t worry too much about the credit, it’s not like anyone should use this for a published game - it’s really only intended as temporary testing solution.

@CJW thanks will do.

Oh boy, this is awesome! :slight_smile:

1 Like

You always realize the oversights after you post something lol…

Although it’ll “work” without further configuration it will only work for ONE game, for e.g. if you play the demo and then play nocturnal_stillness’ unnatural - Unnatural will overwrite your demo save.

The developers of games can fix this by searching for all instances of “mygame_save” in save.js and replacing it with a unique id, like “unnatural_game”.

This is a really easy thing to do if you use the find and replace tool - Sorry about that - It’s something I didn’t consider during testing as I only had the one game.

@CJW thanks for the heads up!

and you have a credit in the game now (just choose Game information :slight_smile: )

@Nocturnal_Stillness Really don’t worry about it, a lot of the code is just reusing stuff already in the interpreter - and I know it’s not a suitable solution for publication, so I feel bad expecting credit for it.

It’s just a simple means to a simple end.

It is actually possible to do a bit more with it but it requires a hell of a lot of editing the core stuff (which would screw with games and be hard to tutorial). At a later date I plan to - possibly - take requests (from established games/authors) for more personalised instances with named save slots and options to make it non-automatic etc.

You’ll see something similar in the next update of Terminal.

CJW, you’re pretty amazing.

I do not have a game in progress, so I will most likely not use this. Maybe ever. But. I just felt the need to say that.

Awesome …it’ll come in handy…thanks :slight_smile:

1 Like

@CJW
Yet again, you’ve done a great service to the community. I know that lengthier games will benefit a lot during testing because of this. You have my thanks. ^:)^

1 Like

@CJW

just to let you know, your hard save system stops the following commands from working.

*show_password and *restore_game

That’s true, the save system overwrites some core functions, those being two of them.
I can try to ammend that, but it could make installation more tricky.

@CJW

What I might do is ask in my topic whether people prefer to use passwords or the hard save version. Then drop which ever one is the least popular.

@Nocturnal_Stillness - What are the exact symptoms? It is possible to get them working together, it just might require edits to the core files (which for ease of installation and game breaking, I’m trying to avoid).

Well if you try to click the restore via password button it doesn’t work. the screen just flashes and thats it.

Try it in unnatural start a new game then click continue game and restore via password and you’ll see what I mean.

Ah, I see :open_mouth: - I’ll get straight on that!