ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   General Authoring Discussion (https://www.esoui.com/forums/forumdisplay.php?f=174)
-   -   Menu getFunc (https://www.esoui.com/forums/showthread.php?t=6765)

Hoft 01/27/17 02:31 PM

Menu getFunc
 
I have a problem with simple code ((
My menu allways show only default value!
setFunc works right and changes variable
ZO_SavedVars works right and load/saves variable
When I change variable by menu, key bind, slash command, or any other way and returns to menu… it allways show default value! Where is my mistake?

Code:

Addon = {
        name = "Addon",
        Menu = {},
        Vars = {},
        Defaults = {
                ["OnOff"] = true,
        }
};

function Addon.Menu()
        local options = {
                {        type        = "header",
                        name        = "Options",
                        width        = "full"
                },
                {        type        = "checkbox",
                        name        = "Enables add-on",
                        tooltip        = "",
                        getFunc        = function() return Addon.Vars.OnOff end,
                        setFunc        = function(value) Addon.Vars.OnOff =value end,
                        default        = Addon.Defaults.OnOff,
                },
        local menu = LibStub("LibAddonMenu-2.0")
        local panel = {
                type = "panel",
                name = "Add-on",
                displayName = "Add-on",
                author = "autor",
                version = "1",
        }
        menu:RegisterAddonPanel("AddonMenu", panel)
        menu:RegisterOptionControls("AddonMenu", options)
end

function Addon.OnAddOnLoaded( eventCode, addonName )
        if (addonName ~= Addon.name) then return end

        EVENT_MANAGER:UnregisterForEvent(Addon.name, EVENT_ADD_ON_LOADED)

        Addon.Vars = ZO_SavedVars:NewAccountWide( "Addon_Settings" , version , nil , Addon.Defaults )
        Addon.Menu()
end


votan 01/27/17 02:43 PM

version is nil?
should be a number, e.g. 1.

Hoft 01/29/17 01:55 AM

Quote:

Originally Posted by votan (Post 29551)
version is nil?
should be a number, e.g. 1.

Right! Just forgotted to place this variable in example.
But version is assigned in my version of the add-on.

Nearly solved: ZOS bug? getFunc can receive only local variables! Now it works:

Code:

function Addon.Menu()
        local settings=Addon.Vars
        local options = {
                {        type        = "checkbox",
                        name        = "Enables add-on",
                        tooltip        = "",
                        getFunc        = function() return settings.OnOff end,
                        setFunc        = function(value) Addon.Vars.OnOff =value end,
                        default        = Addon.Defaults.OnOff,
                },
end

But now ZO_SavedVars do not saves actual values!

votan 01/29/17 02:35 AM

Quote:

Originally Posted by Hoft (Post 29550)
I have a problem with simple code ((
My menu allways show only default value!
setFunc works right and changes variable
ZO_SavedVars works right and load/saves variable
When I change variable by menu, key bind, slash command, or any other way and returns to menu… it allways show default value! Where is my mistake?

The problem is not directly with your code.
Addon is a global variable and "Addon_Settings" is not really a unique name. If you have to save Addon.Vars to a local variable, you have a global variable conflict.
Somebody else is using Addon as a global variable. Make Addon local.

Hoft 01/29/17 04:32 PM

Name «Addon» I used only in this exapmle

Baertram 01/29/17 05:34 PM

Please post the code with the names etc. that is not working and not some "placeholders".
It's easier to check it then.

From what I can see so far there shouldn't be any problem with your code if you use a global "unique" addon name.
There shouldn't be any reason to locally re-assign your global addon variables then just so the addon saves them.

Do you have applied the "SavedVariables" name in your manifest txt file of the addon? It must be the same name that you use in your addon: Addon_Settings


All times are GMT -6. The time now is 04:58 AM.

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