[Done] script.on_configuration_changed question

Place to get help with not working mods / modding interface.
Post Reply
TheSAguy
Smart Inserter
Smart Inserter
Posts: 1263
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

[Done] script.on_configuration_changed question

Post by TheSAguy » Sun Dec 16, 2018 11:09 pm

Does "script.on_configuration_changed" only fire if my mod's version changes?
Or does it trigger if other mods or the game version changes also?

Thanks,
Last edited by TheSAguy on Mon Dec 17, 2018 5:46 pm, edited 1 time in total.

User avatar
Bilka
Factorio Staff
Factorio Staff
Posts: 1161
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: script.on_configuration_changed question

Post by Bilka » Sun Dec 16, 2018 11:59 pm

Api doc wrote:This is called any time the game version changes, prototypes change, startup mod settings change, and any time mod versions change including adding or removing mods.
TL;DR:
TheSAguy wrote:
Sun Dec 16, 2018 11:09 pm
Does "script.on_configuration_changed" only fire if my mod's version changes?
No
TheSAguy wrote:
Sun Dec 16, 2018 11:09 pm
Or does it trigger if other mods or the game version changes also?
Yes
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

TheSAguy
Smart Inserter
Smart Inserter
Posts: 1263
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

Re: script.on_configuration_changed question

Post by TheSAguy » Mon Dec 17, 2018 5:00 pm

Okay, thanks Bilka,

I was wondering how I should handle the following.

I'm adding some global variables that I populate with the initial game settings. As an example:

Code: Select all

global.settler_Group_min_size_NE = game.map_settings.enemy_expansion.settler_group_min_size
So I only want to capture the Initial game setting, and not current running game, since the value might not be the same.
So I'm thought to only add this in the "script.on_init" phase. Knowing that that only runs on a new game (or first time you install the mod)

The problem with this is, if you update the mod from a previous version, the global setting will be missing.

So how do I only run my capturing script for a new game and ignore it if you update the mod in an existing game?

Thanks,

User avatar
Bilka
Factorio Staff
Factorio Staff
Posts: 1161
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: script.on_configuration_changed question

Post by Bilka » Mon Dec 17, 2018 5:42 pm

TheSAguy wrote:
Mon Dec 17, 2018 5:00 pm
So how do I only run my capturing script for a new game and ignore it if you update the mod in an existing game?
The on config changed event gives you https://lua-api.factorio.com/latest/Con ... hangedData. You can use that to see if your mod existed:

Code: Select all

script.on_configuration_changed(function(event) 
  if (not event.mod_changes["your mod name"]) or event.mod_changes["your mod name"].old_version then
    -- your mod was already installed
  end
end)
not event.mod_changes["your mod name"] - your mod didnt change
event.mod_changes["your mod name"].old_version - old version exists, so your mod already existed in the save.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

TheSAguy
Smart Inserter
Smart Inserter
Posts: 1263
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

Re: script.on_configuration_changed question

Post by TheSAguy » Mon Dec 17, 2018 5:46 pm

Thanks Bilka, appreciate the help!

Post Reply

Return to “Modding help”

Who is online

Users browsing this forum: No registered users and 2 guests