I am devloping a mod. One of the features is, that the recipe for "electronic-circuit", defined in the base mod, can be disabled
(data.lua)
Code: Select all
data.raw.recipe["electronic-circuit"].enabled = false
data.raw.recipe["electronic-circuit"].normal.enabled = false
data.raw.recipe['electronic-circuit'].expensive.enabled = false
This works fine for new games. But the problem is, that the change is not applied to loaded savegames. I had a hard time figuring out that the engine reacts differently on changes in data.lua when starting a new game and when loading a saved game (see viewtopic.php?f=25&t=58253 ).
After learning that, the next question was, how I can make the engine also apply the changes to savegames when they are loaded. After searching the web, forum and api-doc, the candidate was script.on_configuration_changed(...) ( http://lua-api.factorio.com/latest/LuaB ... on_changed ). But nothing worked as I hoped. So I did a systematic and painfully long and detailed empirical study on what works and what does not.
The executive summary of the solutions that worked is:
force.reset_technology_effects()
(control.lua)
Code: Select all
script.on_configuration_changed(function(ConfigurationChangedData)
if ConfigurationChangedData.mod_startup_settings_changed == true then
for _,force in pairs(game.forces) do
force.reset_technology_effects()
end
end
end)
Ok, sure, but I was on the search for something that automatically applies all changes made in data.lua .
(control.lua)
Code: Select all
script.on_configuration_changed(function(ConfigurationChangedData)
if ConfigurationChangedData.mod_startup_settings_changed == true then
for _,force in pairs(game.forces) do
force.recipes['electronic-circuit'].enabled = false
end
end
end)
Attempts that did not work
Here is the studies raw data:
Headache inducing details
Question before i mark this thread as solved:Is the use of force.reset_technology_effects() in on_configuration_changed() the intended and complete way to update loaded savegames? Or is this something that lead to other problems later on / in other situations?
Thanks!