Page 1 of 1
[Done] script.on_configuration_changed question
Posted: Sun Dec 16, 2018 11:09 pm
by TheSAguy
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,
Re: script.on_configuration_changed question
Posted: Sun Dec 16, 2018 11:59 pm
by Bilka
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
Re: script.on_configuration_changed question
Posted: Mon Dec 17, 2018 5:00 pm
by TheSAguy
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,
Re: script.on_configuration_changed question
Posted: Mon Dec 17, 2018 5:42 pm
by Bilka
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.
Re: script.on_configuration_changed question
Posted: Mon Dec 17, 2018 5:46 pm
by TheSAguy
Thanks Bilka, appreciate the help!