Code: Select all
if game.active_mods["alien-biomes"] then
Code: Select all
Error while running event my-mod::on_load()
__my-mod__/control.lua:25: attempt to index global 'game' (a nil value)
Code: Select all
if game.active_mods["alien-biomes"] then
Code: Select all
Error while running event my-mod::on_load()
__my-mod__/control.lua:25: attempt to index global 'game' (a nil value)
Strange that it works in 0.18! The following is from the decription of the the data lifecycle:GOKOP wrote: ↑Tue Jun 23, 2020 1:27 pm So in my mod I want to check if alien biomes is active:
This is run in control.lua a function that's called in on_init and on_load. When I load a world last saved in 0.18, everything is fine. But when I load a world last saved in 0.17, I get this error:Code: Select all
if game.active_mods["alien-biomes"] then
And the stack trace points to the line shown in the code snippet.Code: Select all
Error while running event my-mod::on_load() __my-mod__/control.lua:25: attempt to index global 'game' (a nil value)
How about storing a flag? Put this in on_init and on_configuration_changed:During the script.on_load() event handler access to the game table is not available. This handler is meant for only 3 things:
1. Re-setup meta-tables. Meta-tables are not persisted through save-load.
2. Re-setup conditional event handlers (subscribing to an event only when some condition is true to save processing time).
3. Create local references to data stored in the global table
Attempting to change the contents of the global table during the script.on_load() event handler is not allowed. Doing so can lead to desyncs if the mod is used in multiplayer and will generate an error if the game detects it has been changed in any way.
Code: Select all
global.alien_biomes = game.active_mods["alien-biomes"] and true or false
Code: Select all
if global.alien_biomes then … end
Actually I haven't been saving any games while testing so it's not impossible that on_load was never called. I'm new to modding this game and I'm not too sure when it is called and when it's not.Pi-C wrote: ↑Tue Jun 23, 2020 1:47 pm Strange that it works in 0.18! The following is from the decription of the the data lifecycle:
That's also good to know, thanks!Bilka wrote: ↑Tue Jun 23, 2020 2:01 pm https://lua-api.factorio.com/latest/Lua ... ctive_mods can be used in on_load in 0.18, it is not available in 0.17.