ChoiceScript Saving Plugin (Update: April 2023)

Haha this is so old but I love you I forgot to put the .js on the end of “smPluginMenuAddon” goddamn you’re my hero.

1 Like

EDIT: Oh my gosh never mind I fixed it! All I had to do was delete an incomplete *sm_init I had in my startup file a few lines below the completed version, and it booted up just fine! And I’ve tested the load/save features and it all works perfect! :slight_smile: I guess I forgot to delete it from when I was messing with the placement order in relation to all the *creates and stuff!

Okay so I got the SMPlugin.js and SMPluginMenuAddon.js, and I put them in the proper folders and I used notepad++ to open SMPlugin and put my gameid into it, and I also put sm_init into my startup.txt, as well as wrote the proper script direct things into the INDEX file, so that’s all good. But what isn’t good is I’m getting an error now that says:

“SaveMod: Non existent game_id argument for *init_savemod!”

I don’t know what this even is or where to go to even fix it! Please help? Did I have to put *init_savemod into my startup file too, like under sm_init or what?

I don’t recall that you need to do anything with the plugin files itself :thinking:

All you need to do is:

  1. Grab the .js plugin files
  2. Edit the index.html to include the plugin
  3. Edit your startup.txt to include the *sm_init command

Undo that. *sm_init does it for you these days. You don’t need to touch any js files.

Nah, you know? I think it’s about time to edit the first post to lead ppl to the latest plugin post. And probably try to simplify the installation steps.
:v:t4:

I’m having…uh…well…

…yeah. The save system isn’t popping any errors, and the game loads…something, but it’s corrupted. I’m not an expert, but I’m pretty sure there should only be one “Next” button.

I’ve been debugging this on my own for a couple hours now and I’m at my wit’s end. I’ve worked with a fresh download of ChoiceScript in the example game, modifying only startup.txt, smPlugin.js, and index.html.

In index.html, I added the following line (after scene.js and ui.js):

<script src="../smPlugin.js"></script>

in smPlugin.js, I game my game a unique game ID without touching anything else:

game_id: "save_tester",

And here’s my entire startup.txt (170 lines total, click to reveal):

startup.txt
*title Save System Tester 9000
*author Your Face
*scene_list
  startup
  animal
  variables
  gosub
  ending
  death

*create leadership 50
*create strength 50
*create current_save_slot 1
*create loading false

*sm_init save_tester | 3

*label start

This game is licensed under the ChoiceScript License (CSL) v1.0 as a noncommercial work. To view a copy of this license, 
*link http://www.choiceofgames.com/LICENSE-1.0.txt click here.

Choose an option, then press "Next" to confirm.

*label A
*choice

  *selectable_if (((savemod_slot_1 = "No Data") or (savemod_slot_2 = "No Data")) or (savemod_slot_3 = "No Data")) #New Game.
    *comment *set sound true
    Select an empty save slot.

    *choice

      *selectable_if (savemod_slot_1 = "No Data") #Slot 1: ${savemod_slot_1}
        *set current_save_slot 1
        *comment *goto_scene c0_introductions
        *goto test

      *selectable_if (savemod_slot_2 = "No Data") #Slot 2: ${savemod_slot_2}
        *set current_save_slot 2
        *comment *goto_scene c0_introductions
        *goto test

      *selectable_if (savemod_slot_3 = "No Data") #Slot 3: ${savemod_slot_3}
        *set current_save_slot 3
        *comment *goto_scene c0_introductions
        *goto test

      #Return to Main Menu.
        *goto start


  *selectable_if (((savemod_slot_1 != "No Data") or (savemod_slot_2 != "No Data")) or (savemod_slot_3 != "No Data")) #Continue.
    *comment *set sound true
    Select a save slot to load.

    *choice

      *selectable_if (savemod_slot_1 != "No Data") #Slot 1: ${savemod_slot_1}
        *set current_save_slot 1
        *set loading true
        *sm_load 1 | false
        *goto loading

      *selectable_if (savemod_slot_2 != "No Data") #Slot 2: ${savemod_slot_2}
        *set current_save_slot 2
        *set loading true
        *sm_load 2 | false
        *goto loading

      *selectable_if (savemod_slot_3 != "No Data") #Slot 3: ${savemod_slot_3}
        *set current_save_slot 3
        *set loading true
        *sm_load 3 | false
        *goto loading

      #Return to Main Menu.
        *goto start


  *selectable_if (((savemod_slot_1 != "No Data") or (savemod_slot_2 != "No Data")) or (savemod_slot_3 != "No Data")) #Delete A Save.
    Select a save slot to delete.

    *choice

      *selectable_if (savemod_slot_1 != "No Data") #Slot 1: ${savemod_slot_1}
        *sm_delete 1
        *goto start

      *selectable_if (savemod_slot_2 != "No Data") #Slot 2: ${savemod_slot_2}
        *sm_delete 2
        *goto start

      *selectable_if (savemod_slot_3 != "No Data") #Slot 3: ${savemod_slot_3}
        *sm_delete 3
        *goto start

      #Cancel and return to Main Menu.
        *goto start


*label test
Your majesty, your people are starving in the streets, and threaten revolution.
Our enemies to the west are weak, but they threaten soon to invade.  What will you do?

*choice
  #Make pre-emptive war on the western lands.
    If you can seize their territory, your kingdom will flourish.  But your army's
    morale is low and the kingdom's armory is empty.  How will you win the war?
    *choice
      #Drive the peasants like slaves; if we work hard enough, we'll win.
        Unfortunately, morale doesn't work like that.  Your army soon turns against you
        and the kingdom falls to the western barbarians.
        *goto test2
      #Appoint charismatic knights and give them land, peasants, and resources.
        Your majesty's people are eminently resourceful.  Your knights win the day,
        but take care: they may soon demand a convention of parliament.
        *goto test2
      #Steal food and weapons from the enemy in the dead of night.
        A cunning plan.  Soon your army is a match for the westerners; they choose
        not to invade for now, but how long can your majesty postpone the inevitable?
        *goto test2
  #Beat swords to plowshares and trade food to the westerners for protection.
    The westerners have you at the point of a sword.  They demand unfair terms
    from you.
    *choice
      #Accept the terms for now.
        Eventually, the barbarian westerners conquer you anyway, destroying their
        bread basket, and the entire region starves.
        *goto test2
      #Threaten to salt our fields if they don't offer better terms.
        They blink.  Your majesty gets a fair price for wheat.
        *goto test2
  #Abdicate the throne. I have clearly mismanaged this kingdom!
    The kingdom descends into chaos, but you manage to escape with your own hide.
    Perhaps in time you can return to restore order to this fair land.
    *goto test2


*label test2
*set loading false

*if current_save_slot = 1
  *sm_save 1 | false
  *goto test3
*elseif current_save_slot = 2
  *sm_save 2 | false
  *goto test3
*elseif current_save_slot = 3
  *sm_save 3 | false
  *goto test3
*else
  *bug Invalid variable at scene startup, label test2, statement 1, inputs: ${current_save_slot}


*label test3

*if loading
  Loading...

  *page_break
  
  Loaded!
  
  *finish
*else
  *finish

*label loading
*comment blank label so ChoiceScript doesn't complain, doesn't like #choices/*if statements that end in *sm_load

So far, I’ve tried:

  • Adding *if statements to check if the game is loading (pointless in hindsight, as loading overrides the checked variable)
  • Moving *sm_init around (no dice)
  • Adding save slots (the slots work, but the saves are still corrupted)
  • Adding a *goto to a blank *label immediately after *sm_load (errors stopped popping up, but saves were still corrupted)
  • Changing the point of save (corrupts no matter where I put it)
  • Adding a *page_break immediately after *sm_load (maybe my computer was just slow? No, it wasn’t)
  • Virgin sacrifices (volcano god didn’t know either)

I’m throwing in the towel. I need help. Anyone know what’s up?

smPlugin works by overriding some core CS functions so it’s always plausible that’s it’s just buggy.
I’ll take a quick look.

1 Like

Iirc, Dan updated the choicescript so it’ll properly reads ${} in *stat_chart bars.

Doubt that would have had much affect, but perhaps some recent change might have. I can see the problem you’re having @Spectrum, but I can’t see as to why just yet. It seems to work OK using the smPluginMenuAddon… Which is strange, as that just makes calls to smPlugin under the hood.

Right. It’s not your save routines. Took me a while to realise this as well. It’s your loads that are the problem, you’re triggering an implicit *finish by jumping to the end of the file, whilst simultaneously trying to load back to the middle of it.

Just add the ++ lines, as below (without the ++'s):

*label loading
*comment blank label so ChoiceScript doesn't complain, doesn't like #choices/*if statements that end in *sm_load
++ Loaded.
++ *page_break Continue

That gets you back to roughly where you need to be, might still need to tweak it a bit, depending on your exact use case.

1 Like

Good news: it’s fixed, you’re amazing. Bad news: I’ve found more problems.

  1. So I’ve managed to complete the ChoiceScript example game from a save without any problems. However, on loading the save again in the same session, I get stuck in a loop. When I complete the animals scene, the scene repeats when I press Next Chapter. When I press “Restart” and reload the save, I have the same problem…but when I refresh the page, it works perfectly. Even though it’s supposedly the same save.

  2. In addition, I’ve had some buggy behavior with the “Show Stats” and “Settings” buttons. I can’t reproduce it reliably, but sometimes the buttons break after loading. And sometimes, when I view my stats immediately after loading, I cause the animals scene to loop on the first playthrough. However…

  3. …all this might not be smPlugin’s fault, because the “Show Stats” and “Settings” buttons are buggy as is. In a completely vanilla ChoiceScript install, playing the sample game, I can glitch out the buttons by clicking “Show Stats”, then “Settings” in that order:

It’s a minor visual glitch, but it could be wrecking something behind the scenes. Not an expert, but it seemed relevant, and I’d hate to waste your time. Right now, your *page_break solution is good enough for a long form game, though I’ll probably edit the load message to warn players not to view stats/settings immediately. Still trying to isolate what exactly the player should avoid; I’ll post again if I get more info.

EDIT: Oh, great. It put me in the loop after a refresh. But when I refreshed again, it worked fine. Exact same procedure, different results. Maybe it has to do with click speed?

Same for when you are in Stats menu and save the game. YOu can reload it but it will just say show stats instead of get back… So when pressed it does nothin except changing from show stats to go back

Yes, don’t save in the stats screen. That’s what the menu addon is for (global saving).

@CJW Hi I’m new here and needs a little help. How do I make a hidden save without the notification popping up? I just plan to do a very frequent autosave and with the notification happening Everytime that’s just annoying.

I am experiencing difficulties with adding this plugin. I have followed the steps above, yet the save options do not appear. I am using Firefox.

Here is my index.html file alteration:

Summary

script src="…/util.js">
link href="…/style.css" rel=“stylesheet” type=“text/css”>
style id=“dynamic”>
script src="…/ui.js">
script src="…/scene.js">
script src="…/smPlugin.js">
script src=…/smPluginMenuAddon.js">
script src="…/navigator.js">
script src=“mygame.js”>
(I have removed the < from the head of the code lines)

I have added *sm_init WelspringOrigin | 3 to my startup.txt file.

I am not sure where I went wrong, and would be most grateful if someone could provide insight into this issue. Thank you in advance.

Does CS prompt any error messages on game start? Could be that you forgot to include smPluginMenuAddon.js file, that way smPlugin.js will load, but neither the save system will work, nor any errors will occur.

1 Like

The game starts normally, and no errors occur. I have placed both the smPlugin.js and smPluginMenuAddon.js files in my web folder.

And if you temporary remove just the smPlugin.js from the folder and start the game, are there any errors?

1 Like

This error appears: startup line 662: Non-existent command ‘sm_init’

It doesn’t mention that “smPlugin.js is required”? There should be 2 errors.