Someone is getting the below error on loading a new game:. It's on code that's been around a long time, so not sure if a new Factorio release changed anything:
Code: Select all
205.288 Error ServerMultiplayerManager.cpp:95: MultiplayerManager failed: "Error while running on_init: Error while running event Natural_Evolution_Buildings::on_research_finished (ID 18)
__Natural_Evolution_Buildings__/control.lua:556: attempt to perform arithmetic on field 'deduction_constant' (a nil value)
stack traceback:
...mapps/common/Factorio/temp/currently-playing/control.lua:787: in function 'set_research'
...mapps/common/Factorio/temp/currently-playing/control.lua:122: in function 'init_forces'
...mapps/common/Factorio/temp/currently-playing/control.lua:22: in function <...mapps/common/Factorio/temp/currently-playing/control.lua:19>"
This is out of my scope of knowledge, but thought I'd post it here.eradicator wrote:That error is from the wave defense scenario. Looking at that one can see that it uses research_all_technologies which raises on_research_finished during it's own on_init. You can also see that in the error message. Meaning that your on_research_finished handler gets called before your own on_init. Or at least that would be my guess. A workaround would be to initialize your constant during the research event. But it feels a bit buggy that the scenario gets to init before the mods....(bug report-ish?)
The code I'm using is:
On Init:
Code: Select all
if global.deduction_constant == nil or global.deduction_constant == 0 then
global.deduction_constant = 0.00025 -------- DEDUCTION CONSTANT
end
Code: Select all
---------------------------------------------
script.on_event(defines.events.on_research_finished, function(event)
if research == "TerraformingStation-2" then
global.deduction_constant = global.deduction_constant + (global.deduction_constant / 4)
end
if research == "TerraformingStation-3" then
global.deduction_constant = global.deduction_constant + (global.deduction_constant / 4)
end
end)
Thanks.