Page 1 of 1

Auto-resetting tech with "Research Complete" event?

Posted: Sat Dec 05, 2015 11:57 pm
by Reika
I tried to make an infinitely-researchable tech (not just registering thousands of individual techs, but one that resets itself upon completion for true infinity). I used the event system, particularly the "on research complete" event to accomplish this. However, even though the event fires, the research remains "completed". No error is thrown, the code just appears to do nothing. Is the flag I unset only set after the event is fired (and is there any chance that could be changed)?

The relevant code:

Code: Select all

require "defines"
require "util"

script.on_event(defines.events.on_research_finished, function(event)
	if event.research.name == "evo-factor" then
		reduceEvolution()
		
		--reset tech so it can be researched again, ad infinitum
		game.player.force.technologies['evo-factor'].researched=false
	end
end)

Re: Auto-resetting tech with "Research Complete" event?

Posted: Wed Dec 09, 2015 6:26 pm
by Afforess
Reika wrote:I tried to make an infinitely-researchable tech (not just registering thousands of individual techs, but one that resets itself upon completion for true infinity). I used the event system, particularly the "on research complete" event to accomplish this. However, even though the event fires, the research remains "completed". No error is thrown, the code just appears to do nothing. Is the flag I unset only set after the event is fired (and is there any chance that could be changed)?

The relevant code:

Code: Select all

require "defines"
require "util"

script.on_event(defines.events.on_research_finished, function(event)
	if event.research.name == "evo-factor" then
		reduceEvolution()
		
		--reset tech so it can be researched again, ad infinitum
		game.player.force.technologies['evo-factor'].researched=false
	end
end)
I haven't actually looked, but my immediate guess is the game hasn't finished processing the research, so after the event, researched = true is set by Factorio. Try setting the technology researched = false 1 tick after the event and see if that works. Something like this:

Code: Select all

require "defines"
require "util"

local reset_evo_factor = false

script.on_event(defines.events.on_research_finished, function(event)
	if event.research.name == "evo-factor" then
		reduceEvolution()
		
		--reset tech so it can be researched again, ad infinitum
		reset_evo_factor = true
	end
end)

script.on_event(defines.events.on_tick, function(event)
	if reset_evo_factor then
		reset_evo_factor = false
		game.forces['player'].technologies['evo-factor'].researched=false
	end
end)

Re: Auto-resetting tech with "Research Complete" event?

Posted: Wed Dec 09, 2015 10:20 pm
by Reika
That worked. Thank you!


That said, it would be nice if the flag was set before the event was fired, since the tickhandler-style reset is a bit kludgy.