ChoiceScript Saving Plugin (Update: Sept. 2019)

How? isn’t * comment serve no purpose beside to remind you of certain parts while writing?

Yes. Therefore *commenting them out means that the code no longer reads that section. (But it’s easy enough to delete the *comments once you’ve finished the tests)

hey, I’m trying to find a save system so I can test my game (it takes to long to start over every time, which is actually great because it means I am starting to make progress) anyway, I tried to use your links, but I get

Error (509)
This account’s public links are generating too much traffic and have been temporarily disabled!

Does that mean I just have to try again tomorrow or that the link doesn’t work anymore?

Yes, sorry I seem to have hit my daily bandwidth, but it should work again just fine tomorrow!
Apologies for the inconvenience.

Well, I can hardly complain to you for helping now can I. Well, I guess I did do that a little bit, but will try again tomorrow :grinning:

Thanks to @CJW, this is the basic format of the save system I just added to Somme Trench:

1. create save variables for all the normal variables.
    *create one
    *create two
    *create three
    *create save_one
    *create save_two
    *create save_three
    *create savemarker “none”
2. create a saving subroutine that simply saves the save_variables as whatever the
regular variables are at the time
    *label saving
    *set save_one one
    *set save_two two
    *set save_three three
    *return
3. add a save subroutine wherever in the game you want to have a save checkpoint
(I’ve been putting them at the start of chapters).  This is a separate vignette that should be
listed in startup along with the others.  So the first time is “first,” (or whatever), then the next time is
“second,” and so on.
   *gosub_scene saving
   *set savemarker “first”

4.create a loading subroutine, like saving, that simply does the opposite of the
saving subroutine. That way your variables are reset to the last save point.

  *label loading
  *set one save_one
  *set two save_two
  *set three save_three
  *return
5. have an option to return to the last saved point in the game.  This will send you back to wherever the savemarker says to go.
 Do you want to return to the last saved point?
  *choice
     #No
        *finish
     #Yes
        *gosub_scene loading
        *if savemarker = “first”
          *goto firstscene
        *elseif savemarker = “second”
          *goto secondscene
        *else
          *goto thirdscene

I still not figured out this yet, a little help here? :sob:

I’m not psychic. What exactly do you need help with?

Quoting LadyCass (and You, btw), again :

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

"When I try to open the index file, it opens the game in the browser. I don’t know how to install it as a script.

I’m sure this is really simple, and I just don’t get it.

Thanks so much!"

You need to open it in a text or code-editor, such as notepad or notepad++.
Right click the file and select ‘open with…’, then follow my above instructions.

Apologies for the necro, but I was hoping you might be able to help me with the issue I’m having, as I’ve been at it for over an hour now with no luck. The issue I am having is when I enter the new line of script into the index.html, I can’t seem to get the grey next button to work afterwards, clicking it does nothing.

I am placing the smplugin.js under mygame.js (and generally speaking, I haven’t altered the script order from the original), the syntax is all correct, the js file is definitely in the right directory with the right pathing (I put it in both folders to make sure), and sm_init is in the correct place under all the *create’s with the variables set.

It isn’t throwing up any error codes, it just won’t let me click through to the next scene. As soon as I remove the line from the index.html (and the *sm_init), it works fine again. Suspect it is a general issue, as when I couldn’t get the advanced save working, I tried the earlier save plugin and had the same problem. Anyway, any ideas you may have would be greatly appreciated, stumped over here.

EDIT: Forgot to mention, have tried both with IE and Firefox (up to date versions) and both doing it.

I want to add a save system to my game where a beta-tester can save at any time of his choosing. The smPlugin system will work for this if I add a save #option in each and every *choice. Obviously that’s not ideal, so I thought I could put the save/load/delete menu on the stats screen. However, this seems to restore the game to the stats screen itself, and then I can’t get back to the game. Is there a way to do what I want? Perhaps by making another button next to Show Stats and Achievements?

Would autosave.js not suffice for this?
https://dl.dropboxusercontent.com/u/7840892/CJW/choicescript/code/autosave-plugin/index.html
https://dl.dropboxusercontent.com/u/7840892/CJW/choicescript/code/save.js

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:

[code]
*if debug
*sm_init dragon_princess | 11
*label sm_top
*choice
#Play from the beginning.
*goto sm_done
#Load
*label load
*choice
#{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
#Return
*goto sm_top
#Delete
*label delete
*choice
#{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
#Return
*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.

@Flurrywinde11
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

File

Enjoy!

P.S.
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.

10 Likes

@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

*scene_list
startup
Chapter2
Call

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