[0.16.5] Migrations triggered on mod despite being first time added to save

Bugs that are actually features.
Post Reply
kyranzor
Filter Inserter
Filter Inserter
Posts: 499
Joined: Fri Oct 31, 2014 4:52 pm
Contact:

[0.16.5] Migrations triggered on mod despite being first time added to save

Post by kyranzor »

Hello,
referencing this issue on my mod's github page: https://github.com/kyranf/robotarmyfactorio/issues/125

The game appears to be running very old, unnecessary migration scripts when my mod (v0.3.4 currently) is added to a save game in 0.16 which was started (and saved) without the mod in it. When the mod is activated and the save is loaded, it appears to want to run every old migration script since the dawn of time. Perhaps there's a logical issue where it thinks if the mod is new, the first version was 0.0.0 so it triggers loading migrations all the way up the chain to match the current version?


edit: the documentation at http://lua-api.factorio.com/latest/Migrations.html doesn't specifically state what happens when a mod is added for the first time if any migration scripts will be run.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13242
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.16.5] Migrations triggered on mod despite being first time added to save

Post by Rseding91 »

Thanks for the report. I don't know if this is a bug or not. Both behaviors can be useful but I think the "run all migration scripts on adding the mod to an existing save" (what you're seeing) is more useful.

I'll update the lua docs to say it's will do that.
If you want to get ahold of me I'm almost always on Discord.

kyranzor
Filter Inserter
Filter Inserter
Posts: 499
Joined: Fri Oct 31, 2014 4:52 pm
Contact:

Re: [0.16.5] Migrations triggered on mod despite being first time added to save

Post by kyranzor »

Fair enough.

my thoughts were that if the mod has yet to be added to a save, then there can't possibly be anything to migrate. Perhaps an event could fire like "first_add" or something if it's the first time the mod exists, both in a new game and when first added to a savegame that is already in-progress. Then whatever minor logic can be cleanly handled in that event handler and only once. I think we have this event already isn't it the "init" event or something? Maybe I could put my logic in there.

The logic I can forsee being useful is if a mod is added which has technology-dependent recipes and a user adds them to an existing game where the tech is unlocked, it's not exactly a mod migration it's more of a 'catch up' functionality in the cases where that technology out-of-sync can happen.

If you change the mod and add new stuff in a new version, which depends on technologies that may have already been researched, then it definitely makes sense to keep the logic to fix this issue in the migration scripts like we currently do.

mrvn
Smart Inserter
Smart Inserter
Posts: 5710
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: [0.16.5] Migrations triggered on mod despite being first time added to save

Post by mrvn »

That's exactly how I understand on_init and on_load to work. on_init is only called when the mod is added to the game.

Post Reply

Return to “Not a bug”