Page 1 of 1

Settings defaults for older versions

Posted: Mon Jul 27, 2026 4:37 am
by wanne
I would like to introduce a cost multiplayer to some of my recipes. I would like to have the default for new installations set 5. But on the other hand: The one that equals the old recipes would be 10.
So I would like to set the value to 10 if the mod is updated from a older version to not break ratios.
Is there a nice way to do this via migrations? If I just set it in the migrations/foo.lua every subsequent update would set the value to 10.

So I am searching for something like a check witch version was the last one?

Re: Settings defaults for older versions

Posted: Mon Jul 27, 2026 10:14 am
by davidsonmonster
I don't think migrations expose the previous mod version directly. A common approach is to check whether your global setting or data already exists, and only initialize it if it's `nil`. That way new installs get the default value of 5, while existing saves can keep or migrate to 10 without overwriting it on every update.

Re: Settings defaults for older versions

Posted: Wed Jul 29, 2026 7:47 am
by wanne
If I understand it right a check for nil will always fail because the migrations stage is executed after the settings stage that sets the value to 5.

Re: Settings defaults for older versions

Posted: Wed Jul 29, 2026 12:11 pm
by robot256
The default value of the setting is set during the settings stage and the recipe ratio is set during the data stage. Both are completed before the game loads to menu and cannot be changed automatically based on what save file is subsequently loaded.

The best you can do is a warning message that prints in on_configuration_changed telling that detects when the save was migrated from a 10x version but the seeing is 5x. It can tell the player to not save the game and go change the setting if they want it to stay the same.