Page 1 of 1

on_configuration_changed on mod update

Posted: Wed Sep 21, 2016 6:31 pm
by AntiElitz
I would like to run code when my mod gets updated, but on_configuration_changed only fires on factorio update or mod add/removal. May you also make it fire on mod update?

Re: on_configuration_changed on mod update

Posted: Wed Sep 21, 2016 6:46 pm
by Adil
Are you sure?
http://lua-api.factorio.com/0.14.8/LuaB ... on_changed
[quote=api]This is called any time the game version changes and any time mod versions change including adding or removing mods.[/quote]

Re: on_configuration_changed on mod update

Posted: Wed Sep 21, 2016 7:02 pm
by aubergine18
Lots of mods use the event to update internal state (eg. stuff on `global`) when they have been updated. It definitely works. Something like this:

Code: Select all

script.on_configuration_changed( function(event)
  local changed = event.mod_changes and event.mod_changes["your-mod-name"]

  if changed then -- something to do with your mod

    if not changed.old_version then
      -- your mod was added
    elseif not changed.new_version then
      -- your mod was removed
    else
      -- your mod was updated
    end

  end
end )

Re: on_configuration_changed on mod update

Posted: Wed Sep 21, 2016 8:18 pm
by AntiElitz
strange it doesn't trigger for me, but when i update factorio. Probably I did a misstake in my code than. Thx guys

Re: on_configuration_changed on mod update

Posted: Wed Sep 21, 2016 9:08 pm
by aubergine18
Did you get any errors when your script ran? Also, how were you testing that it was working? In that particular event it's usually best to use the global `log()` function to output stuff to game log (as game.players[id].print won't be available) in some cases.