Thread Tools Display Modes
05/31/22, 02:27 PM   #1
Lykeion
 
Lykeion's Avatar
AddOn Author - Click to view addons
Join Date: May 2022
Posts: 17
registerForDefaults doesn't work as expected

Greetings.

I've recently coded my first addon Much Smarter AutoLoot and seems it gets the job done not bad. Yet I faced a problem that I can't make the build-in function registerForDefaults, which is provided by LibAddonMenu works on my addon.
When I click the Default button in my addon panel and confirm in the confirmation box, nothing happens. The options aren't set to default, nor does the confirmation box disappear. Literally, nothing happens.

I can't find out what causes this problem. I gave every panel option default and set registerForDefaults true, but for some reason, LibAddonMenu cannot reset them.

Code:
...
local panelData = 
{
	type = "panel",
	name = GetString(MSAL_PANEL_NAME),
	displayName = GetString(MSAL_PANEL_DISPLAYNAME),
	author = "|c215895Lykeion|r",
	version = "|ccc922f2.2.0|r",
	slashCommand = "/msal",
	registerForRefresh = true,
	registerForDefaults = true
}

...

local optionsData = 
{	
...
	{
		type = "submenu",
		name = GetString(MSAL_LOOT_FILTERS),
		controls = {
			[1] = {
				type = "slider",
				name = GetString(MSAL_QUALITY_THRESHOLD),
				tooltip = GetString(MSAL_QUALITY_THRESHOLD_TOOLTIP),
				min = 1,
				max = 5,
				step = 1,
				getFunc = function() return db.minimumQuality end,
				setFunc = function(value) db.minimumQuality = value end,
				default = 1,
			},
			[2] = {
				type = "slider",
				name = GetString(MSAL_VALUE_THRESHOLD),
				tooltip = GetString(MSAL_VALUE_THRESHOLD_TOOLTIP),
				min = 0,
				max = 10000,
				getFunc = function() return db.minimumValue end,
				setFunc = function(value) db.minimumValue = value end,
				default = 10,
			},
			[3] = {
				type = "dropdown",
				name = GetString(MSAL_ORNATE_ITEMS),
				tooltip = GetString(MSAL_ORNATE_INTRCATE_TOOLTIP),
				choices = defaultChoices,
				choicesValues = defaultChoicesValues,
				getFunc = function() return db.filters.ornate end,
				setFunc = function(value) db.filters.ornate = value end,
				default = "always loot",
			},
			[4] = {
				type = "dropdown",
				name = GetString(MSAL_INTRICATE_ITEMS),
				tooltip = GetString(MSAL_ORNATE_INTRCATE_TOOLTIP),
				choices = defaultChoices,
				choicesValues = defaultChoicesValues,
				getFunc = function() return db.filters.intricate end,
				setFunc = function(value) db.filters.intricate = value end,
				default = "always loot",
			},
		...
	}
	...
}

LAM2:RegisterAddonPanel("MuchSmarterAutoLootOptions", panelData)
LAM2:RegisterOptionControls("MuchSmarterAutoLootOptions", optionsData)
...
My SVs typically look like this. I don't know whether SVs' structure could make an impact on registerForDefaults' function, but someone told me it is good to keep nested tables away from SVs if you want to reset options to default later. I tried expanding the nested table["filters"] in my SVs but it didn't solve this problem. Considering nested tables haven't raised any problems till now, I keep them intact in SVs temporarily.

Code:
MSAL_VARS =
{
    ["NA Megaserver"] = 
    {
        ["@userId"] = 
        {
            ["Id"] = 
            {
            ["$AccountWide"] = 
            {
                ["Account"] = 
                {
                    ["lootStolen"] = false,
                    ["allowDestroy"] = false,
                    ["minimumQuality"] = 4,
                    ["printItems"] = false,
                    ["filters"] = 
                    {
                        ["potions"] = "always loot",
                        ["collectibles"] = "always loot",
                        ["jewelry"] = "always loot",
                        ["foodAndDrink"] = "never loot",
                        ["ornate"] = "always loot",
                        ["furnitureCraftingMaterials"] = "always loot",
                        ["tickets"] = "never loot",
                        ["craftingMaterials"] = "always loot",
                        ["containers"] = "always loot",
                        ["costumes"] = "never loot",
                        ["soulGems"] = "always loot",
                        ["runes"] = "always loot",
                        ["fishingBaits"] = "never loot",
                        ["ingredients"] = "always loot",
                        ["glyphs"] = "never loot",
                        ["styleMaterials"] = "always loot",
                        ["intricate"] = "always loot",
                        ["crystals"] = "always loot",
                        ["armors"] = "per quality threshold",
                        ["recipes"] = "always loot",
                        ["tools"] = "always loot",
                        ["poisons"] = "never loot",
                        ["weapons"] = "per quality threshold",
                    },
                    ["closeLootWindow"] = false,
                    ["version"] = 1,
                    ["minimumValue"] = 10,
                    ["enabled"] = true,
                    ["LibSavedVars"] = 
                    {
                        ["accountSavedVarsActive"] = true,
                    },
                },
            },
        },
    },
}

Last edited by Lykeion : 05/31/22 at 02:53 PM.
  Reply With Quote
05/31/22, 02:33 PM   #2
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,567
Did you set "registerForDefaults" on the panel like mentioned on the wiki?
  Reply With Quote
05/31/22, 02:40 PM   #3
Lykeion
 
Lykeion's Avatar
AddOn Author - Click to view addons
Join Date: May 2022
Posts: 17
Originally Posted by sirinsidiator View Post
Did you set "registerForDefaults" on the panel like mentioned on the wiki?
Yes I do. I added some code for further information
  Reply With Quote
05/31/22, 02:51 PM   #4
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,567
LAM simply calls your setFunc and passes the default value from the data table to it. Maybe you can add a log output to your setFunc to check if it is really not calling it?
  Reply With Quote
05/31/22, 03:05 PM   #5
Lykeion
 
Lykeion's Avatar
AddOn Author - Click to view addons
Join Date: May 2022
Posts: 17
Originally Posted by sirinsidiator View Post
LAM simply calls your setFunc and passes the default value from the data table to it. Maybe you can add a log output to your setFunc to check if it is really not calling it?
I added log output in setFunc and it does print the value each time I change it. I think that means setFunc is doing its job. Is there something else could happen between pressing the Reset button and calling setFunc?
  Reply With Quote
05/31/22, 03:35 PM   #6
Lykeion
 
Lykeion's Avatar
AddOn Author - Click to view addons
Join Date: May 2022
Posts: 17
Originally Posted by sirinsidiator View Post
LAM simply calls your setFunc and passes the default value from the data table to it. Maybe you can add a log output to your setFunc to check if it is really not calling it?
I found out it might be caused by my enable option, which asks for a setFunc value but never use it. After I removed it from the options the registerForDefaults works well! Thanks for your inspiration

Code:
...
[1] = {
	type = "checkbox",
	name = GetString(MSAL_ENABLE_MSAL),
	tooltip = GetString(MSAL_ENABLE_MSAL_TOOLTIP),
	getFunc = function() return db.enabled end,
	setFunc = function(value) self:ToggleAutoLoot() end,
	default = true,
},
...
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » registerForDefaults doesn't work as expected

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off