Help making my mod: How to make things persist across configuration changes?

Place to get help with not working mods / modding interface.
User avatar
Maoman
Inserter
Inserter
Posts: 22
Joined: Sat Nov 12, 2016 10:55 am
Contact:

Help making my mod: How to make things persist across configuration changes?

Post by Maoman »

My mod https://mods.factorio.com/mod/SARS/downloads unlocks alternate recipes. It currently does save what recipes you unlock. However, every time the configuration changes such as when I update the mod, it erases all the unlocked recipes and I don't know why or how to make it stop. Can anyone help me?

It tries to reunlock the recipes, I think, because the console prints out
[SARS] Unknown key: "sars-alt-unlocked-manual" <name of recipe>
for each recipe that I previously had unlocked. But it doesn't actually unlock them. Anyone have an idea? It will print out the localisation key correctly if I access it in-game with the lua console so I don't think it's a localisation file issue, despite what the error suggests.

Attached is the latest version that I'm working with.
robot256
Smart Inserter
Smart Inserter
Posts: 1237
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: Help making my mod: How to make things persist across configuration changes?

Post by robot256 »

When the configuration changes, the game automatically recalculates which recipes should be unlocked based on all the technologies that have been researched. That way, if a mod adds a new recipe to an early tech, it gets unlocked immediately.

In your case, the recipes are not unlocked by any technology, so the game automatically re-locks them during its scan. One way to fix this could be to make a hidden technology that your mod marks as researched when you unlock a recipe. That way the scan will see that it should be unlocked without you having to do anything.

Depending on when you mean to unlock them, you might be able to use the "trigger research" options to have the game automatically research the tech and unlock the recipe when a certain item is obtained, for example.

If all that fails, then your best option is to add code in on_configuration_changed to read from storage what recipes should be locked and unlocked for each force, and manually restore them.
My mods: Multiple Unit Train Control, RGB Pipes, Shipping Containers, Rocket Log, Smart Artillery Wagons.
Maintainer of Auto Deconstruct, Cargo Ships, Vehicle Wagon, Honk, Shortwave.
Post Reply

Return to “Modding help”