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

Place to get help with not working mods / modding interface.
Post Reply
TheSAguy
Smart Inserter
Smart Inserter
Posts: 1449
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

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

Post 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.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

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

Post 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?)
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

TheSAguy
Smart Inserter
Smart Inserter
Posts: 1449
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

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

Post 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.

Post Reply

Return to “Modding help”