Mod Settings Won't Update
-
- Manual Inserter
- Posts: 2
- Joined: Sat May 22, 2021 8:10 pm
- Contact:
Mod Settings Won't Update
I can't be entirely sure if this is a bug or an error on my part, but I've tried everything I can think of to fix this on my own and I'm out of options. I'm editing a mod I found and I can barely get any changes to the mod settings (map / global) to work. I've found a process where I can get the values to update if I 1: disable the mod, 2: save, load, and quit the world, then 3: re-enable the mod and change the settings, but once I save the world again, I'm unable to change the settings again. It keeps the new values in the settings menu, but the new values aren't applied to the world. I've also added print statements to confirm that the values in `settings.global` do indeed stay the same, and this is in version 1.1.110.
- Attachments
-
- TrainSpeeds.zip
- mod
- (1.85 MiB) Downloaded 18 times
-
- bugged world.zip
- world
- (10.48 MiB) Downloaded 29 times
Re: Mod Settings Won't Update
Thanks for the report however I can't reproduce any issue. I can load that save, go to mod settings, change a a value, go back to the game, and print it - and it's changed as expected.
No amount of saving/loading breaks anything.
Can you please give the exact steps you're doing and or record a video of it not working for you?
No amount of saving/loading breaks anything.
Can you please give the exact steps you're doing and or record a video of it not working for you?
If you want to get ahold of me I'm almost always on Discord.
Re: Mod Settings Won't Update
I looked at your mod code and you are not handling the on_runtime_mod_settings_changed event at all. You also are using session global variables instead of savefile globals, and trying to recreate the entire table of trains and settings inside on_load because of that. This is not multiplayer-compatible and will most likely cause desyncs.
The way that works in all of my mods is:
1. Create empty tables in global.* inside on_init instead of in the Lua session
2. Cache settings into e.g. global.mysettings in on_init, on_configuration_changed and on_runtime_mod_setting_changed
3. Clear and repopulate the global.* tables of trains etc in on_configuration_changed
4. Do essentially nothing in on_load.
This will result in the mod being save-load agnostic, which is important because when a player joins a game, the client runs on_load at that tick though the server ran it when the server started running. This way the Lua session state will remain the same between client and server no matter what happens.
The way that works in all of my mods is:
1. Create empty tables in global.* inside on_init instead of in the Lua session
2. Cache settings into e.g. global.mysettings in on_init, on_configuration_changed and on_runtime_mod_setting_changed
3. Clear and repopulate the global.* tables of trains etc in on_configuration_changed
4. Do essentially nothing in on_load.
This will result in the mod being save-load agnostic, which is important because when a player joins a game, the client runs on_load at that tick though the server ran it when the server started running. This way the Lua session state will remain the same between client and server no matter what happens.
My mods: Multiple Unit Train Control, Smart Artillery Wagons
Maintainer of Vehicle Wagon 2, Cargo Ships, Honk
Maintainer of Vehicle Wagon 2, Cargo Ships, Honk