Migration help

Place to get help with not working mods / modding interface.
Post Reply
vedrit
Filter Inserter
Filter Inserter
Posts: 292
Joined: Sun Aug 03, 2014 2:25 am
Contact:

Migration help

Post by vedrit »

Hey all,
I'm trying to figure out how to trigger a function in control.lua from migration (or, alternatively, via on_load or on_init) but nothing seems to work. The function iterates through a global table and replaces entities based on research done. I've put in print commands to try and debug, but they don't seem to be popping up and the entities do not appear to have been replaced.
If I try to put the contents of the function directly into my migration lua file, then I get a bad argument error ('pairs' (table expected, got nil)) on the line where I start a for loop.
If I try to set a global boolean and check it elsewhere, or try to call the function, nothing happens.
Any help would be appreciated!

eduran
Filter Inserter
Filter Inserter
Posts: 344
Joined: Fri May 09, 2014 2:52 pm
Contact:

Re: Migration help

Post by eduran »

Try this https://lua-api.factorio.com/latest/Lua ... on_changed instead of on_load or on_init. The even is raised every time mod configuration changes.

vedrit
Filter Inserter
Filter Inserter
Posts: 292
Joined: Sun Aug 03, 2014 2:25 am
Contact:

Re: Migration help

Post by vedrit »

eduran wrote:
Mon Feb 04, 2019 9:01 am
Try this https://lua-api.factorio.com/latest/Lua ... on_changed instead of on_load or on_init. The even is raised every time mod configuration changes.
Just tried that, no luck. It's weird, because it works for another mod I have included, and I used it as a guide.

Code: Select all

script.on_configuration_changed(configChanged)

local function configChanged(event)
	game.print("Game state changed")
	update_walls()
end

eduran
Filter Inserter
Filter Inserter
Posts: 344
Joined: Fri May 09, 2014 2:52 pm
Contact:

Re: Migration help

Post by eduran »

Change the order around. A local variable (or function) is only visible from the point of its definition onward. So by the time you call script.on_configuration_changed configChanged does not exist yet.

vedrit
Filter Inserter
Filter Inserter
Posts: 292
Joined: Sun Aug 03, 2014 2:25 am
Contact:

Re: Migration help

Post by vedrit »

eduran wrote:
Mon Feb 04, 2019 9:20 am
Change the order around. A local variable (or function) is only visible from the point of its definition onward. So by the time you call script.on_configuration_changed configChanged does not exist yet.
Ah, there we go. Thanks!

User avatar
Therenas
Factorio Staff
Factorio Staff
Posts: 232
Joined: Tue Dec 11, 2018 2:10 pm
Contact:

Re: Migration help

Post by Therenas »

As a side note, on_load() should only be called in very specific instances, otehrwise it leads to desync. Also, you can't use game.print() in the on_init() function, because on_init() is called before the world is fully loaded.

vedrit
Filter Inserter
Filter Inserter
Posts: 292
Joined: Sun Aug 03, 2014 2:25 am
Contact:

Re: Migration help

Post by vedrit »

Therenas wrote:
Mon Feb 04, 2019 10:48 am
Also, you can't use game.print() in the on_init() function, because on_init() is called before the world is fully loaded.
Yeah, learned that after I got things working

Post Reply

Return to “Modding help”