A handy utility script for addon developers using MCM. Simple-to-configure storage for options in the players savefile.
NOTE
This is included with MCM as of MCM version 1_4 (MCM 1_4 UPDATE 1_4 25MAY21). I now recommend not distributing this script with your addon, since end-users will have it already present by installing MCM 1_4. Instead you should specify that your addon requires at least version 1_4 of MCM. However, if you want to get support or report a bug, this is where you should do it.
You can now also use `ui_mcm.store_in_save(path)` instead of calling the script directly. See ui_mcm.script for additional documentation.
This doesn't do anything on its own. It's purely for addon developers who want a simple solution to storing and retrieving their MCM configuration options in the players savefile.
- Usage instructions in the script file. (It's just calling one function, simple as I said).
- Save to use for existing savefiles, and save to remove for savefiles with stored data in them as well.
- If you include it in your addon, the script file can be overwritten by other addons doing the same without problem.
- You may distribute this together with your addon, as long as you keep the script header intact.
- No need to credit me, unless you want to.
Changelog
1.2
- Added support for arbitrary paths(thanks for the idea ravenascendant).
"You may distribute this together with your addon, as long as you keep the script header intact."
I'm tempted to do just that when i update to fix the collections bug :)
Sure, sounds great! Speaking of collections: This script can't handle them -- I might update it to do that when I find time. But since I haven't seen anyone else use that feature yet I doubt too many people will have a problem.
Also, I've been using your fix (j instead of i) locally and haven't experienced a single bug. It also didn't make any problems when I was adding a menu without collection in-between my collection menus. Apart from that I didn't do any testing, just normal usage.
If you implement support for arbitrary path length then it would be dph_mcm_save_storage.register_module("collection/example_example")
this would also lead in to support for specifying individual options that a moddev would like saved to the save rather than all or nothing.
You're right, that's way more elegant and simple. I've updated the script.
You now have a credit in MCM. I did alias the function into mcm for clarity/brevity sake, but ppl that are calling it directly will have no problems as I did not edit your script in any way.
Perfect, thanks for the credit.
Will it break savegame compatibility?
No, when the script loads a modules state, it will check whether an entry in the mdata table exists for it, and skip it if that isn't the case (resulting in unchanged MCM options -- the same they were before loading the savegame). When it saves a modules state it will also do a check for nil, and initialize the appropiate entry in the mdata table the first time it's run for a given savegame.
You can safely remove the script and still load savegames with MCM options in it, it'll just be dead data. You can also remove the data from a savegame, and that'll only result in losing the stored MCM options.
EDIT:
The relevant code for both checks is at lines 76 and 91 if you want to take a look yourself.
Nope it uses the Marshal library to store information in the .coc portion of your save file. Abandoned data there is never read out and very unlikely to break any thing.