superloading settings.lua
Posted: Fri Mar 08, 2019 12:56 am
tl;dr: What is the correct way to add settings to the menu in an addon?
I'm trying to add a new tab to the Game Options menu (in retrospect, it should probably be a new entry in the main menu but I'll deal with that later), but there seems to be an issue preventing my settings from being initialized.
My superload of settings.lua is very simple:
But I get the error that "config.settings.playerai" is a nil value.
My theory is that the line at the top of settings.lua:
Is being run when the main menu is loaded, and the addon is not loaded (addons being loaded upon New Game), and therefore my superload is never called.
Should I be hanging this init code off of a different file/class? What's the best way to ensure this code is properly run? Maybe call it from bindHook("ToME:run") or bindHook("ToME:load") perhaps?
EDIT: Are there other details to consider during this, such as explicit saving of the new settings? Should I instead be storing things in config.settings.tome.playerai so that things like save/load are handled more automatically?
I'm trying to add a new tab to the Game Options menu (in retrospect, it should probably be a new entry in the main menu but I'll deal with that later), but there seems to be an issue preventing my settings from being initialized.
My superload of settings.lua is very simple:
Code: Select all
config.settings.playerai = config.settings.playerai or {}
-- set defaults for the player ai
if type(config.settings.playerai.health_threshold) == 'nil' then config.settings.playerai.health_threshold_stop = 0.25 end
if type(config.settings.playerai.health_threshold) == 'nil' then config.settings.playerai.health_threshold_flee = 0.50 end
My theory is that the line at the top of settings.lua:
Code: Select all
if config.settings.tome_init_settings_ran then return end
config.settings.tome_init_settings_ran = true
Should I be hanging this init code off of a different file/class? What's the best way to ensure this code is properly run? Maybe call it from bindHook("ToME:run") or bindHook("ToME:load") perhaps?
EDIT: Are there other details to consider during this, such as explicit saving of the new settings? Should I instead be storing things in config.settings.tome.playerai so that things like save/load are handled more automatically?