ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   General Authoring Discussion (https://www.esoui.com/forums/forumdisplay.php?f=174)
-   -   registerForDefaults doesn't work as expected (https://www.esoui.com/forums/showthread.php?t=10201)

Lykeion 05/31/22 02:27 PM

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,
                    },
                },
            },
        },
    },
}


sirinsidiator 05/31/22 02:33 PM

Did you set "registerForDefaults" on the panel like mentioned on the wiki?

Lykeion 05/31/22 02:40 PM

Quote:

Originally Posted by sirinsidiator (Post 46005)
Did you set "registerForDefaults" on the panel like mentioned on the wiki?

Yes I do. I added some code for further information

sirinsidiator 05/31/22 02:51 PM

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?

Lykeion 05/31/22 03:05 PM

Quote:

Originally Posted by sirinsidiator (Post 46007)
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?

Lykeion 05/31/22 03:35 PM

Quote:

Originally Posted by sirinsidiator (Post 46007)
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,
},
...



All times are GMT -6. The time now is 05:19 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI