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!
Migration help
Re: Migration help
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.
Re: Migration help
Just tried that, no luck. It's weird, because it works for another mod I have included, and I used it as a guide.eduran wrote: ↑Mon Feb 04, 2019 9:01 amTry 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.
Code: Select all
script.on_configuration_changed(configChanged)
local function configChanged(event)
game.print("Game state changed")
update_walls()
end
Re: Migration help
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.
Re: Migration help
Ah, there we go. Thanks!
Re: Migration help
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.
Re: Migration help
Yeah, learned that after I got things working