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

Place to get help with not working mods / modding interface.
dalindes
Inserter
Inserter
Posts: 27
Joined: Sun Jan 23, 2022 8:02 pm
Contact:

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

Post 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. :)
User avatar
Osmo
Fast Inserter
Fast Inserter
Posts: 205
Joined: Wed Oct 23, 2024 12:08 pm
Contact:

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

Post 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).
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3751
Joined: Tue May 13, 2014 11:06 am
Contact:

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

Post 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")
dalindes
Inserter
Inserter
Posts: 27
Joined: Sun Jan 23, 2022 8:02 pm
Contact:

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

Post 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!
dalindes
Inserter
Inserter
Posts: 27
Joined: Sun Jan 23, 2022 8:02 pm
Contact:

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

Post 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!
Post Reply

Return to “Modding help”