on_configuration_changed + attempt to index upvalue '_ENV' ?
Posted: Mon Jan 29, 2018 10:04 pm
I'm working on a benchmarking/testing scenario file and mod. When the mod's present, I want to use its event hooks which it publishes with a remote interface. When the mod's absent I want to use the fallback event hooks in the scenario's control.lua.
Running, without the mod present, a scenario saved with the mod present, aborts in the on_configuration_changed hook, with the title error.
the log message is
and when I look in the save files's control.lua that's the `local e=defines.events[on_s]` line in
and I don't understand that at all.
The api docs say
Running, without the mod present, a scenario saved with the mod present, aborts in the on_configuration_changed hook, with the title error.
Code: Select all
function configuration_changed(...)
if (remote.interfaces.BenchmarkProduction or empty).insta
then
on('marked_for_deconstruction')
on('built_entity')
for n = 1,#game.players do
remote.call('BenchmarkProduction','insta',{player_index=n})
end
else
on('marked_for_deconstruction',instakill)
on('built_entity',instabuild)
end
end
on('configuration_changed',configuration_changed)
Code: Select all
------------- Error -------------
Error while running on_configuration_changed: /home/quyxkh/.factorio/temp/currently-playing/control.lua:26: attempt to index upvalue '_ENV' (a nil value)
---------------------------------
Code: Select all
local bootstraps={init=1,load=1,configuration_changed=1}
function on (s,f)
local on_s ='on_'..s
local e = defines.events[on_s]
if e then
notrace[e]=true
return script.on_event(e,f)
elseif bootstraps[s] then
return script[on_s](f)
else -- a custom input
return script.on_event(s,f)
end
end
The api docs say
Will someone please point out what I'm missing here? If I can't check in on_load and can't check in on_configuration_changed, when can I check? Or alternately, if o-c-c is the right place, how should I be doing it?. control.lua script.on_configuration_changed()
When mods are changed (prototypes added or removed), the major game version changes, a mod version changes, a mod is removed, or a mod is added the script.on_configuration_changed() event is fired for each mod subscribed to that event.
This is the main place for handling mod internal data structure changes. Access to the global table, game table and game state are available and can be changed in any way seen fit by the mod.