ChoiceScript Saving Plugin (Update: April 2023)

Would autosave.js not suffice for this?

Wow, I see there are buttons for it at the top, but it only saves your current place. How hard would it be to make a Save button at the top to call *sm_save? That’s pretty much what I’m looking for.

BTW, in the autosave example index.html, if I hit restart, I get: Uncaught exception: ReferenceError: Undefined variable: alertify

I think I figured out how to do it myself:

< button id=“saveButton” class=“spacedLink” onclick=“Scene.prototype.sm_save(‘0 | true’);”>Save< /button>

However, if I load a game (using a *choice block much like your example), then hit the Save button after playing a little further, nothing happens. I have to hit it again, and then it saves correctly. Any ideas why that might be happening?

Here’s the code at the beginning of startup.txt (after all *create’s) that does the loads:

*if debug
*sm_init dragon_princess | 11
*label sm_top
#Play from the beginning.
*goto sm_done
*label load
#{savemod_slot_0} *sm_load 0 | false *goto sm_done #{savemod_slot_1}
*sm_load 1 | false
*goto sm_done
#{savemod_slot_2} *sm_load 2 | false *goto sm_done #{savemod_slot_3}
*sm_load 3 | false
*goto sm_done
#{savemod_slot_4} *sm_load 4 | false *goto sm_done #{savemod_slot_5}
*sm_load 5 | false
*goto sm_done
#{savemod_slot_6} *sm_load 6 | false *goto sm_done #{savemod_slot_7}
*sm_load 7 | false
*goto sm_done
#{savemod_slot_8} *sm_load 8 | false *goto sm_done #{savemod_slot_9}
*sm_load 9 | false
*goto sm_done
#{savemod_slot_10} *sm_load 10 | false *goto sm_done #{savemod_slot_11}
*sm_load 11 | false
*goto sm_done
*goto sm_top
*label delete
#{savemod_slot_0} *sm_delete 0 *goto delete #{savemod_slot_1}
*sm_delete 1
*goto delete
#{savemod_slot_2} *sm_delete 2 *goto delete #{savemod_slot_3}
*sm_delete 3
*goto delete
#{savemod_slot_4} *sm_delete 4 *goto delete #{savemod_slot_5}
*sm_delete 5
*goto delete
#{savemod_slot_6} *sm_delete 6 *goto delete #{savemod_slot_7}
*sm_delete 7
*goto delete
#{savemod_slot_8} *sm_delete 8 *goto delete #{savemod_slot_9}
*sm_delete 9
*goto delete
#{savemod_slot_10} *sm_delete 10 *goto delete #{savemod_slot_11}
*sm_delete 11
*goto delete
*goto sm_top

*label sm_done[/code]

Quick Note: smPlugin.js (and likely save.js) don’t seem to be compatible with the latest version of CS. So either don’t update your game until I push a fix or remove the reference to the mod(s) from your index.html file (if you’re having problems with unresponsive page_breaks and choices etc).

Update: I’ve not tested it extensively, but I believe the issue should be fixed now.
Please let me know if any of you run into any further problems.

Sorry, I must have missed this. I have no idea though I’m afraid, it’s not something I ever thought to try.

This works perfectly for me. Thank you so much for making something like this! Its easy and a lifesaver!

1 Like

Update: smPlugin - Menu Addon

Due to what seemed like an increasingly popular demand I’ve thrown in the towel and finally written an ‘addon’ for smPlugin that provides an interface for your game so that players can save games ‘on the fly’ - much like they would usually be able to in visual novels and the like.

With thanks to @Malebranche for the idea and design:

It’s very easy to use, simply download and include the smPluginMenuAddon.js file in your index.html (BENEATH smPlugin.js - you do need both files!), run your game and after 3 seconds or so the buttons and slot selection should appear and function as intended.

Note that you do still need to use *sm_init on the first page of your game to initialize your slots and game id - that is extremely important!

Other than that the addon should do the rest for you, though you can of course still use the smPlugin.js core commands, if you want to make an autosave or the like (just make sure you tell your players which slots you’ll be overwriting!).

If at any point you want to be cruel and disable saving you can also use the extra command:

*sm_menuaddon false

And of course, to re-enable saving:

*sm_menuaddon true



This addon (in my eyes) makes save.js all but redundant, so unless there are any complaints I’ll be considering discontinuing support for that rendition of the mod.


@CJW Wow this is amazing, you deserve huge props for the time and effort put into this! Unfortunately, i find myself a little bit confused as to how you’re meant to declare *sm_init. I’ve scrolled up and looked through previous responses hoping to find the answer hidden somewhere in this thread, but I haven’t been able to find anything.

I’ve downloaded and included smPlugin.js as well as smPluginMenuAddon.js is my index file:

And I’ve used *sm_init on the first page of my game as such:
*sm_init Song_Of_The_Fallen | 3

*title Song_Of_The_Fallen
*author Left4Bed


However unless I remove *sm_init Song_Of_The_Fallen | 3 I get this error.

I suspect this is because I really just don’t quite understand what you mean when you say:

I’m sorry if this is a stupid question.

Same thing happened to me when I first downloaded, turns out you need to put it right before your story exposition starts after all the *create commands and everything in startup.txt.

1 Like

@Malebranche Which *creates are you referring to?

*create strength 50 *create otherstat "" Those ^^ at the beginning of your startup.txt file after the scene list. The *create command is for your global (or constantly used) stats.

So under all my stats and before any exposition, I’ve added *sm_init Song_Of_The_Fallen | 3. Song_Of_The_Fallen is what I’ve put as my game_id in smPlugin.js with a slotCount of 3. But now it’s throwing up this error.

Which is strange since I added both of those to my index file? I added it to the index file in the mygame folder since the one in the web folder doesn’t seem to have anywhere for me to put it. I did the same thing for the original save.js system that began this thread, and that worked fine. I’ve also placed copies of smPlugin.js and smPluginMenuAddon to both the mygame folder and the web folder.

Reading up, specifically looking at what @Flurrywinde11 posted, I get the impression that you’re also supposed to declare *sm_load and sm_save? I’ve also fiddled with the quick-save-menu .zip folder @CJW linked to in another thread, but to no avail.

So you have a copy of each one in the mygame & in the web folder (4 files in total 2 of each)?

Yes, but the error comes up either way. You say you’ve manged to get it working? Is there any chance i could see a snippet of your relevant code?

I only have 1 copy of each, placed within my web folder, like so:

In index.html:

And in startup.txt:

That’s pretty much exactly, what mine is…which index file did you edit?

The one in the mygame folder.

Still throws up the same error, though it also throws up this.

I’m downloaded the lastest version of choicescript from the website and I’m busy updating my firefox, hopefully that’ll have some effect, because as far as I can tell we’re doing exactly the same thing.

If you remove smPluginMenuAddon.js from your index.html for a bit, save index.html, and double click index to open it, does it still throw up the localStorage error?

Yup except now that’s the only error it throws up, and what’s really weird is I managed to get it sort of working on the folder I mentioned earlier (which I just realised is actually from your Saving “on the fly” topic). So figured I could just move my scene files over that and see what happens, and it threw this up.

I’m starting to think it’s just not meant to be.

Ok, then if it’s still throwing up that particular error, it’s probably your browser (which you said you already updated)… Do you have any settings on your browser such as “do not accept cookies from 3rd party websites” checked?