Thread Tools Display Modes
Prev Previous Post   Next Post Next
05/31/22, 02:27 PM   #1
Lykeion
 
Lykeion's Avatar
AddOn Author - Click to view addons
Join Date: May 2022
Posts: 21
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
 

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


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