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:
Code:
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
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:
Code:
if config.settings.tome_init_settings_ran then return end
config.settings.tome_init_settings_ran = true
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?
_________________
Currently developing the
Player AI addon. You can get it from the
T-Engine Addon Hub or
SteamYou can also
view the source code.