on_configuration_changed on mod update

Things that already exist in the current mod API
Post Reply
AntiElitz
Filter Inserter
Filter Inserter
Posts: 446
Joined: Sat Aug 29, 2015 11:37 pm
Contact:

on_configuration_changed on mod update

Post 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?

User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

Re: on_configuration_changed on mod update

Post 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]
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.

User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: on_configuration_changed on mod update

Post 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 )
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.

AntiElitz
Filter Inserter
Filter Inserter
Posts: 446
Joined: Sat Aug 29, 2015 11:37 pm
Contact:

Re: on_configuration_changed on mod update

Post 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

User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: on_configuration_changed on mod update

Post 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.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.

Post Reply

Return to “Already exists”