Page 1 of 1

"Error while running on_init: Error while running event Natural_Evolution_Buildings::on_research

Posted: Sun Jan 28, 2018 4:22 pm
by TheSAguy
Hi,

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>"
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
And when finishing research:

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)

Since I'm initializing "deduction_constant", I'm not sure why it's saying it's nil.
Again, this has been working for a long time.

Thanks.

Re: "Error while running on_init: Error while running event Natural_Evolution_Buildings::on_research

Posted: Mon Jan 29, 2018 12:56 am
by eradicator
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?)

Re: "Error while running on_init: Error while running event Natural_Evolution_Buildings::on_research

Posted: Mon Jan 29, 2018 5:13 pm
by TheSAguy
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?)
Thanks Eradicator, appreciate you looking into this! I'll escalate.