Fetching mod runtime settings on save load

Place to get help with not working mods / modding interface.
M.Colcko
Inserter
Inserter
Posts: 21
Joined: Sun Dec 04, 2016 7:23 am
Contact:

Fetching mod runtime settings on save load

Post by M.Colcko »

I have a per user mod setting. Changing it while the save is loaded works as it should using the on_runtime_mod_setting_changed event. However, I am unsure how to check the setting on save load. on_runtime_mod_setting_changed doesn't get called when a save is loaded. And now if the user is in the main menu, changes the mods setting and loads the game, this change isn't reflected in game.

The on_load bootstrap event won't work, since that's quite restricted.

How can I fetch my mods setting, and act accordingly on save loadup?
Rseding91
Factorio Staff
Factorio Staff
Posts: 14598
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Fetching mod runtime settings on save load

Post by Rseding91 »

That is all working correctly. By default the "Use mod settings per save" is enabled which means changing per-player settings from the main menu when a game is not loaded only has an effect on new save files. If the player disables that setting; loading a save will call 'on_runtime_mod_setting_changed', or if a player changes the setting while the save is loaded.

There's nothing you need to do different.
If you want to get ahold of me I'm almost always on Discord.
M.Colcko
Inserter
Inserter
Posts: 21
Joined: Sun Dec 04, 2016 7:23 am
Contact:

Re: Fetching mod runtime settings on save load

Post by M.Colcko »

Ah, I see. Yeah, turning off per-save mod setting triggers the event. Thank you.

A different question: What would be the best way to run a function on save load, If I want to read/write to global?
FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2768
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: Fetching mod runtime settings on save load

Post by FuryoftheStars »

You cannot write to global during load:
https://lua-api.factorio.com/latest/Lua ... ap.on_load
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles | New Gear Girl & HR Graphics
M.Colcko
Inserter
Inserter
Posts: 21
Joined: Sun Dec 04, 2016 7:23 am
Contact:

Re: Fetching mod runtime settings on save load

Post by M.Colcko »

I know. I'm not looking to use on_load but rather a way to execute some code somewhere on the first few ticks after the save has been loaded.
robot256
Filter Inserter
Filter Inserter
Posts: 995
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: Fetching mod runtime settings on save load

Post by robot256 »

That's not really allowed, though. Code executing inside the game should never change its behavior based on when a game was saved and loaded, or it will lead to desyncs (every client loads the save at a different time when they join, and even their player-specific GUi elements need to exist the same on every client). You get events when settings or mods change, and those sometimes happen coincidentally with save loads, but that's it.
FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2768
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: Fetching mod runtime settings on save load

Post by FuryoftheStars »

Yeah, unless someone else has a better idea, I’d suggest evaluating what it is that you’re actually trying to accomplish and why, and whether or not it’s actually needed (ie, do you really need to check the status of a mod setting on “load” instead of the change event?).
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles | New Gear Girl & HR Graphics
M.Colcko
Inserter
Inserter
Posts: 21
Joined: Sun Dec 04, 2016 7:23 am
Contact:

Re: Fetching mod runtime settings on save load

Post by M.Colcko »

That's unfortunate. Thanks for the help! I'll try to find a different approach to my problem
Post Reply

Return to “Modding help”