ChoiceScript Saving Plugin (Update: April 2023)

so when is the new type of save system coming?

Wow, I’m glad this was bumped as I hadn’t seen it. I guess it’s on the wiki too and I missed it? Should be stickied for certain.

Typical that IE9 has issues with it, however, I think I’ll try implementing this once I’ve reached the end of the chapter on my wip.

@CJW - thanks for this, where would COG be without all of your helpful hacks/fixes/tips?

@akatsuki9344 It shouldn’t be too long now, all the functionality is there, I just want to ensure it catches incompatible browser configurations and problems without crashing the game.

@bawpie I’m really glad you like it! But it isn’t on the wiki just yet, and only the basic version is available to download.

@CJW - read the whole thread after posting (d’oh) so I see a more advanced version is in the works. I’ll stick with what I have for now, but will certainly implement the flashier version when it’s out!


You can see the flashier version in my game I’m @CJW s guinea pig for it lol

@Nocturnal_Stillness - that’s really nice, can’t wait for it to be released. Btw, you might want to update your game link on the wiki as it’s broken :slight_smile:

1 Like

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

Release - smPlugin.js

The new ‘framework’ save system is done.

I don’t currently have the time or willpower to write up proper documentation for it.

There’s a demo here, which should be enough to grasp the general concept:

Demo Code

Instructions and Basic Info in a Nutshell

  • Uses browser localStorage to store/restore generated between browser sessions on the same computer/device. Older browsers, some mobile browsers etc do not support localStorage.

  • If a browser doesn’t support localStorage the system shouldn’t stop your game from working, it’ll only inform the player they can’t save - not actually “crash” - let me know if it does.


Must be used before any other sm commands, right at the top of your first scene file is ideal. This initializes the system, checks for previous saves etc.

It takes two arguments, the name of your game and the number of save slots.
Try to choose these two values carefully when you first implement this system and stick with them. Changing the game name will result in loss of your player’s saves.

*sm_init mygame | 5

Does exactly what it says on the tin. Saves the game (if it can).
This one takes three arguments, the first two are compulsory and the last one is optional.

The first one is the slot number the game should save to, it HAS to be a “number” and it has to be a WHOLE number - it also has to be between 0 and your number of slots (as declared with sm_init).

*sm_save 3

The second argument on sm_save is the type of save, there’s two:

Hidden Saves & Shown Saves

Hidden saves will just save like that without any input from the player, nor any notification that a save has taken place.

Shown saves will prompt the player to save (but he can decline), it’ll also allow them to rename a save, if they so wish.

Shown Save to slot 3
*sm_save 3 | true

Hidden Save to slot 3
*sm_save 3 | false

The last argument is optional (the above code examples will work) and is the save name. For both shown and hidden saves you can provide a ‘default’ name for a save - this is particularly useful for hidden saves, where the player cannot rename them themselves.

For example we’re coding our game and come to the end of a chapter - we don’t want to ruin the experience with a big ugly ‘please save’ popup, so we’ll do a hidden save. However, we want the player to know (when loading) exactly where he is - he won’t remember ‘saving’ this one after all.

Hidden Save to slot 2 with a default name
*sm_save 2 | false | End of Chapter 5 - Close Call

Now when the player tries to load a save, this one will appear with that name.
If you don’t provide a default name a time and date will be used instead.

Much like sm_save, sm_load does exactly what you think it does; loads saves.

It takes the same two compulsory arguments as sm_save, the slot number from which it should be loading and the hidden/shown parameter.

Force load a game from slot 3
*sm_load 3 | false

Prompt the player to load a game from slot 3
*sm_load 2 | true

Takes one argument, the slot number.

*sm_delete 1
*sm_delete 2


Again it has to be within the bounds of your defined number of slots, so watch that.
Deletion will ALWAYS prompt the player you can’t silently delete saves, yet. I might add it in if there’s popular demand.

Note on Slots

THINK! This is a do-it-yourself framework, not a automatic system like the save.js - There are many ways and means by which you can use these commands. Experiment a little, find what works for you.

If you’re going to mix manual and ‘automatic’ saving, keep the slots separate. Players won’t be happy if you’re constantly overwriting their manual saves with automatic ones.

Say slot 0 is the automatic slot, don’t allow manual saves to slot 0. Simples.

Have fun, report bugs, make cool games etc etc ^^’

Oh yeah… The system uses the typical js notifcation boxes, not alertify.js’ because IE kept throwing a tantrum and I’d personally rather have the functionality over the aesthetic appeal.


finally you rock !!! thanks very much

@CJW, you are incredible. Thank you for all the work you put into the save system.

1 Like

Fantastic job, @CJW. Thanks, especially, for making it so flexible. I’ve been tinkering with the system for a little while and wanted to confirm a few limitations.

  1. Can’t load mid-scene?
    I can easily save anywhere and load from anywhere, but the game always loads at the beginning of the scene where it saved.

  2. Can’t use variables to name saves?
    For instance, using the player-chosen character name as the default save name causes an error.

I’m not complaining about either of these things. In fact, I’ve already more or less worked around them. I just wanted to make sure it’s not my own stupidity overlooking something obvious. :stuck_out_tongue:

@CS_Closet you can load mid scene I did it in unnatural it autosaves at a midway point and you can load it up from that point.

@CJW: This looks great - I may not implement it in the current game i’m working on since I don’t want to have to tinker around with the fundamental coding too much at this stage, but will certainly be looking to implement it in future :slight_smile:

1 Like

Must just be something I did, then. Probably an issue with my convoluted *gosub routines. Thanks for letting me know it’s possible, though!

@akatsuki9344 @Marius @Largejo

Thanks guys, really looking forward to seeing what people can do with this, be sure to post your games that use it here! And if you get any ideas for improvement or find any bugs, please let me know! :slight_smile:


As @Nocturnal_Stillness says you should be perfectly fine loading and reloading in the middle of a scene, it may be that I’ve changed something since Nocturnal’s version (you may want to upgrade Nocturnal, your version will bug out on a lot of browsers like IE) - so please do let me know if you continue to have problems.

As for the save names - that did occur to me - and I can see why that would be useful for hidden saves, I’ll look further into it!

1 Like

I’ll mess around a bit more with it to see if I can get it to work. Likely, it’s something I did due to not “reading instructions before assembly”, so to speak. :-"

@CJW - this looks very impressive! The earlier version is already excellent, so I’m looking forward to implementing this. Will need to update my choicescript version first, so might save it for when I’ve got the next update for my wip ready. Thanks again!

1 Like

@bawpie You’re very welcome! I look forward to seeing it in action :smiley:

@CS_Closet Not really, I can’t think of any way to ‘use it wrong’ that would result in that behaviour - if you’ve no joy soon, let me no asap and I’ll do some tests.

@CJW - Eh, well…I updated my version of choicescript, downloaded your plugin and placed it in the web folder and amended the index.html to make reference to smPlugin (just under the navigator.js line as per your demo code). I’ve started my startup file with *sm_init but just get an error saying the command doesn’t exist whenever I try to run it?

The first line of my startup file looks like this:

*sm_init healms | 4

I’ve updated the smplugin file to look like this:

saveMod = {
game_id: “healms”
,slotCount: 4
,justLoaded: false

But to be honest, it seems like the plugin just isn’t being picked up? I guess I’m missing something, though I’m not sure what!

The link to my wip is here: - would be very grateful if anyone could point out what I’m doing wrong!

Try changing your smPlugin.js file back to:

saveMod = {
	game_id: ""
    ,slotCount: 3      
    ,justLoaded: false

The *sm_init command at the start of your game file should take care of defining the rest (or that’s what I assumed it did, anyway).

Other than that, I can’t think of anything that you might’ve done differently than I. Your startup.txt file is fine.

@CS_Closet - thanks for the suggestion, I only changed smplugin when I thought that might be the reason it wasn’t working. Changed it back to the default and still no joy :frowning: