ToME: the Tales of Maj'Eyal

Everything about ToME
It is currently Thu Aug 22, 2019 2:49 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Fri Mar 08, 2019 12:56 am 
Offline
Higher

Joined: Wed Jul 22, 2015 8:12 pm
Posts: 62
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 Steam
You can also view the source code.


Top
 Profile  
 
PostPosted: Fri Mar 08, 2019 3:51 am 
Offline
Perspiring Physicist

Joined: Sun Sep 09, 2012 7:43 am
Posts: 5923
Not by Superloading. Bad!

Grab one of my addons, such as Arcanum or Verdant, pull it apart and look near the bottom of the load.lua file.

_________________
My feedback meter decays into coding. Give me feedback and I make mods.


Top
 Profile  
 
PostPosted: Fri Mar 08, 2019 7:50 pm 
Offline
Higher

Joined: Wed Jul 22, 2015 8:12 pm
Posts: 62
The hook onto GameOptions:generateList (or GameOptions:tabs in my case) works great for putting the menu items into the options menu, and I've had that working fine.

The question was how you get those settings into the config object, and how you ensure that these settings are saved.

It turns out I'm doing it basically the same way as you were (except I'm calling other files from load.lua instead of putting it all in directly because I expect it to get messy and large), with one key exception: In the game:saveSettings() function, I spelled the names of my variables wrong. Doh!

Thanks for giving me a working model frustratingly similar to what I had so I could finally make myself read closely enough.

_________________
Currently developing the Player AI addon. You can get it from the T-Engine Addon Hub or Steam
You can also view the source code.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group