Page 1 of 1

Is it possible to rename a mod, but retain storage data?

Posted: Mon Dec 08, 2025 1:35 am
by dalindes
Hi all,

Relative newbie to modding, and... well, I'm doing some work on a mod, and I'd like to change the name (of the directory/zip file, and the "name" field in info.json) of it, but I have some saves that have data from it, and I'd ideally like to somehow keep that data but make it available to the mod under its new name. It seems that the way this is handled ("Each mod has access to its own instance of this table, so there is no need to worry about namespacing", per the docs) doesn't really provide for this, which... mostly makes sense, and... anyway, just wondering if there's a clean way to do this.

I figure there are some options, since I control both old and new versions -- e.g. I could use write_file and either table_to_json or serpent.block to write out a file, then turn that into a lua function that I call in on_init.

This would work for me, and I'm not opposed to doing it, I'm just wondering if there might be some easier way (partly because I've already gone several points beyond this stage when working in new saves, before realizing I wanted to keep data from some old saves, if possible.)

Any tips welcome, including just "yeah, do it with write_file like you said"... but, ya know, hopeful there might be some other hack that I'm not finding that would make it trivially easy to do somehow. :)

Re: Is it possible to rename a mod, but retain storage data?

Posted: Mon Dec 08, 2025 2:05 am
by Osmo
It is not possible directly, and you usually don't need to rename a mod's internal name. You can change the displayed name instead.
But if you want to transfer storage data, you'll have to do it manually since you can only write files, but not read them. You can copy-paste the contents or rename the output to a lua file that returns the contents of serpent.dump (not serpent.block as that's not fully serializable).

Re: Is it possible to rename a mod, but retain storage data?

Posted: Mon Dec 08, 2025 3:03 am
by DaveMcW
You can copy storage with LuaRemote if you have both mods enabled.

Code: Select all

/c __mod1__ remote.add_interface("mod1 getter", { getstorage = function() return storage end })

Code: Select all

/c __mod2__ storage = remote.call("mod1 getter", "getstorage")

Re: Is it possible to rename a mod, but retain storage data?

Posted: Mon Dec 08, 2025 3:49 am
by dalindes
Osmo wrote: Mon Dec 08, 2025 2:05 am you usually don't need to rename a mod's internal name.
Fair enough. I wish to, though; I have my reasons. :)
Osmo wrote: Mon Dec 08, 2025 2:05 am You can copy-paste the contents or rename the output to a lua file that returns the contents...
Yeah, that's what I'd been thinking... glad to see thoughts align...
Osmo wrote: Mon Dec 08, 2025 2:05 am ... of serpent.dump (not serpent.block as that's not fully serializable).
Ooh, thank you! Good distinction. Well, that potentially saved me some heartache; thanks. :)


Meanwhile...
DaveMcW wrote: Mon Dec 08, 2025 3:03 am You can copy storage with LuaRemote if you have both mods enabled.
Oooh, this looks perfect! I haven't tried the mod-context console commands before, but that seems like exactly what I need. Will give it a try soon! (And if you don't hear more, that probably means it worked great, so thank you! If not, I'll share results and/or ask further questions. :) )

Thank you, both!

Re: Is it possible to rename a mod, but retain storage data?

Posted: Mon Dec 08, 2025 6:17 pm
by dalindes
Just confirming, the remote.add_interface/remote.call thing worked great (and serpent.dump helped, too)!

I'd been slightly worried about whether the __modname__ thing would be fine with the characters (not just [a-zA-Z0-9_], but also containing [-]) would be fine, but it wasn't a problem! Cool beans. :)

Thanks again, Osmo and DaveMcW!