[1.1.87] Mod migrations (lua) not running in new save

Place to get help with not working mods / modding interface.
Post Reply
Neutrality
Burner Inserter
Burner Inserter
Posts: 14
Joined: Fri Jan 31, 2020 5:10 am
Contact:

[1.1.87] Mod migrations (lua) not running in new save

Post by Neutrality »

I'm working on a new version of a mod. I updated the version number and added a lua migration file, but it doesn't run when I start a new save, even if I save and reload the game.

It does get applied to existing saves that had an older version of the mod that hadn't run the migration file though, and also to existing save files that didn't have the mod.

I haven't tried json mod migrations and don't know if the same thing happens for json migrations.

Edited to add:
According to https://lua-api.factorio.com/latest/aux ... ve-startup , migrations are run after on_init(), in saves where the mod is considered "new"
... A mod is considered new to the save either when the player starts a new save with the mod enabled, ...
Last edited by Neutrality on Tue Sep 05, 2023 12:26 am, edited 1 time in total.

Pi-C
Smart Inserter
Smart Inserter
Posts: 1654
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: [1.1.87] Mod migrations (lua) not running in new save

Post by Pi-C »

Neutrality wrote:
Mon Sep 04, 2023 10:43 pm
I'm working on a new version of a mod. I updated the version number and added a lua migration file, but it doesn't run when I start a new save, even if I save and reload the game.
Not sure if I understand you correctly: Do you mean you start a new game (migration doesn't run), then save and reload with the same version of the mod and the migration also doesn't run? If so, this is the expected behavior.

Migration scripts are used, for example, if you want to modify your table 'global', make certain entities inactive, etc. Generally speaking, you need a migration if you make a big change to the game state that only needs to be applied once.

If you start a new game, there is no old game state that you'd have to migrate, you can simply use script.on_init to set up the things you need. If you save this game and reload it with the same version of your mod, there also is no need to run any migration because Factorio assumes that the mod contents will be the same if the mod's version number hasn't changed. (That may be frustrating if you want to test your migration script, but can't be helped.)
It does get applied to existing saves that had an older version of the mod that hadn't run the migration file though, and also to existing save files that didn't have the mod.
That's exactly how it should be: If you've updated your mod, you may have introduced some drastic changes that make a migration necessary. If you add the the mod to an existing game, you may have to adjust the game state (e.g. to enable recipes introduced by your mod if they are unlocked by a technology that already has been researched), so a one-time change via a migration script is justified.
I haven't tried json mod migrations and don't know if the same thing happens for json migrations.
Should be the same. These migrations are used if you have renamed prototypes (recipes, technologies, entities, etc.). Without a JSON migration file, the game wouldn't be able to find the renamed prototypes, so it would remove everything that's based on such a prototype: Formerly researched technologies would be unresearched, assembling machines that were producing happily away would be without a recipe, items would disappear from inventories, belts, and GUIs, trains could be split up if they contained one of your modded wagons, … But again, it wouldn't make sense to run the migration when you start a new game where none of your things have been used yet.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Neutrality
Burner Inserter
Burner Inserter
Posts: 14
Joined: Fri Jan 31, 2020 5:10 am
Contact:

Re: [1.1.87] Mod migrations (lua) not running in new save

Post by Neutrality »

Perhaps the issue is only with the wording on https://lua-api.factorio.com/latest/aux ... ve-startup

According to that, migrations are run after on_init(), in saves where the mod is considered "new"
... A mod is considered new to the save either when the player starts a new save with the mod enabled, ...
If this part of the data lifecycle docs page is incorrect, and migrations are not run for new saves, then things are WAI

Post Reply

Return to “Modding help”