Auto-resetting tech with "Research Complete" event?

Place to get help with not working mods / modding interface.
User avatar
Reika
Filter Inserter
Filter Inserter
Posts: 587
Joined: Tue May 19, 2015 1:56 am
Contact:

Auto-resetting tech with "Research Complete" event?

Post 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)
Image
User avatar
Afforess
Filter Inserter
Filter Inserter
Posts: 422
Joined: Tue May 05, 2015 6:07 pm
Contact:

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

Post 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)
User avatar
Reika
Filter Inserter
Filter Inserter
Posts: 587
Joined: Tue May 19, 2015 1:56 am
Contact:

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

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

Return to “Modding help”