Migration scripts: a guide?

Place to get help with not working mods / modding interface.
JasonC
Filter Inserter
Filter Inserter
Posts: 448
Joined: Tue Mar 22, 2016 3:05 am
Contact:

Re: Migration scripts: a guide?

Post by JasonC »

FreeER wrote: I believe (but I am not 100% certain) that lua migration scripts can also access and modify the glob table (so if you previously had a glob.whatever variable that stored an integer and you needed to change it to be a table of integers you could use 'if glob.whatever then glob.whatever={new_index=glob.whatever} else glob.whatever={new_index=default_value} end'.
the lua migration format is exactly the same as the control.lua.
This does not appear to be the case (0.12.29). The global table seems to not be loaded yet (it exists but is empty) when the migration scripts run.

So I guess that means that script.on_configuration_changed is where you have to do it if you're modifying anything in global. I think.
Took a break from 0.12.29 to 0.17.79, and then to ... oh god now it's 1.something. I never know what's happening.

User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2915
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: Migration scripts: a guide?

Post by Optera »

According to this signals are not supported in json scripts.
Is there another way to migrate signal names?

Edit:
As of 0.15.17 signals can be migrated.
Added support for virtual-signal migrations.
Last edited by Optera on Thu Jul 20, 2017 1:40 pm, edited 1 time in total.

User avatar
DRY411S
Filter Inserter
Filter Inserter
Posts: 726
Joined: Sun Mar 13, 2016 9:48 am
Contact:

Re: Migration scripts: a guide?

Post by DRY411S »

Is the migration filename and version number significant?
Must it include the mod name?
And will every version of the migration script run that is less than the current mod version, or do they all run anyway and get flagged as run in the saved game file?

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7351
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Migration scripts: a guide?

Post by bobingabout »

I've just mashed the keyboard before and it worked.

the key thing to remember is that every script can only be run once, and this is filtered by name.

The easiest way to make sure that you only ever run every script once, and make sure you're using a name nobody else has used before, ever, is to name it by the mod name and version number.

A save game will hold the name of every migration script ever run within it, preventing it from running a second time, so every script is run once.

(I'm not entirely sure if scripts are run on creating a new game or not. I think they are)
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2915
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: Migration scripts: a guide?

Post by Optera »

I think I've had migration scripts run again after a clean save. (removing a mod, creating a save without the mod and adding it back)
To me this would imply scripts are saved on a per mod basis.

User avatar
TelemakFactorio
Long Handed Inserter
Long Handed Inserter
Posts: 53
Joined: Fri Oct 14, 2016 4:30 pm
Contact:

Re: Migration scripts: a guide?

Post by TelemakFactorio »

Just for helping

I played with migration today. Factorio 0.16.x. My purpose was to add values in global table between two versions of a mod.

I ended to use on_init and on_configuration_changed, no way for something else, like in earlier version of factorio.

control.lua

Code: Select all

script.on_configuration_changed(
	function ()
		if global.CompBitNbPlayersKilled == nil then
			global.CompBitNbPlayersKilled = 0
		end
		if global.CompBitNbEntitiesDestroyed == nil then
			global.CompBitNbEntitiesDestroyed = {}
		end
	end
)

script.on_init(
	function ()
		global.CompBitNbPlayersKilled = 0
		global.CompBitNbEntitiesDestroyed = {}
	end
)

Post Reply

Return to “Modding help”