Page 1 of 1

on_startup_mod_settings_changed

Posted: Tue May 23, 2017 8:01 am
by bobingabout
I've noticed that since I heavily make use of "startup" options to edit the data table from the mod options, Recipes and Technologies are NOT changed to match what you change the settings to when loading a savegame.

one possible solution is to force a reset_recipes() and reset_technologies() event, as well as actually trigger a "on_startup_mod_settings_changed" event to run the equivalent of a migration script. (though if you trigger an event, reset_recipes() and reset_technologies() don't need to be forced as they can be included in the event.)

EG, if a mod update adds a new entity to the game, and adds that unlock to an existing technology, then you'd have a migration script run like this:

Code: Select all

for index, force in pairs(game.forces) do
  force.reset_recipes()
  force.reset_technologies()

  if force.recipes["bob-distillery"] and force.technologies["electrolysis-1"].researched then
    force.recipes["bob-distillery"].enabled = true
  end
end
What I feel we need is the ability to add something like that in control.lua to be triggered when startup settings have changed.

Basically, what I'm asking for is this event, but for startup settings http://lua-api.factorio.com/latest/even ... ng_changed

EG:

Code: Select all

script.on_runtime_mod_setting_changed(function(event)
  if event.setting == "bobmods-plates-purewater" and settings.startup["bobmods-plates-purewater"].value == true then
    for index, force in pairs(game.forces) do
      force.reset_recipes()
      force.reset_technologies()
      if force.recipes["bob-distillery"] and force.technologies["electrolysis-1"].researched then
        force.recipes["bob-distillery"].enabled = true
      end
    end
  end
end)

Re: on_startup_mod_settings_changed

Posted: Tue May 23, 2017 9:16 am
by Choumiko
Next release will have a flag in on_configuration_changed whether startup settings have changed :)

Re: on_startup_mod_settings_changed

Posted: Tue May 23, 2017 9:50 am
by bobingabout
If on_configuration_changed will be fired when a mod startup setting has changed, then even without checking if it's a mod version, or a setting that has changed, a lazy way could be to include a script like this:

Code: Select all

script.on_configuration_changed(function(event)
  for index, force in pairs(game.forces) do
    force.reset_recipes() --probably not actually needed
    force.reset_technologies() --probably not actually needed

    if settings.startup["bobmods-plates-purewater"].value == true then
      if force.recipes["bob-distillery"] and force.technologies["electrolysis-1"].researched then
        force.recipes["bob-distillery"].enabled = true
      end
    end
    --other setting checks here.
  end
end)
Attempting to unlock a recipe that is already unlocked isn't going to break anything, the worst you're doing here is unlocking things when you don't need to, because they're already unlocked.