WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   AceConfig OptionsTable Radio Help (https://www.wowinterface.com/forums/showthread.php?t=55917)

Smallinger 12-14-17 11:25 AM

AceConfig OptionsTable Radio Help
 
Hello, i working my first time with AceConfig Options Table and AceDB,

if i press on one of the radio i got this error.
Code:

attempt to index field 'repairMode' (a string value)
i have a table with follow information
Code:

local repairModeList = {
        ["1"] = "Own gold",
        ["2"] = "Guild bank",
}

i have under RegusterDefaults a Variable with the name
Code:

self.db:RegisterDefaults({
        char = {
                autoRepair = true,
                printRepairGold = true,
                repairMode = "1",
        }
})

and in the Table for AceConfig OptionsTable a radio like this.

Code:

repairMode = {
        order        = 17,
        type        = "select",
        name    = "Repair mode",
        desc    = "",
        style        = "radio",
        values        = repairModeList,
        get          = function(key) return self.db.char.repairMode[key.arg] end,
        set          = function(key, value) self.db.char.repairMode[key.arg] = value end,
},

i hope anyone can help me..

Ammako 12-14-17 11:40 AM

Well you already set repairMode as a string ("1"), and then you try to reuse it as a table, which is bound to cause issues no matter what for what you're trying to do. :p

Smallinger 12-14-17 12:09 PM

Quote:

Originally Posted by Ammako (Post 326131)
Well you already set repairMode as a string ("1"), and then you try to reuse it as a table, which is bound to cause issues no matter what for what you're trying to do. :p

Hey Ammako thx for your answer, is there a possibility to get the key and safe it as a String ? or is there a better way ?

so that i can check the code with like
Code:

if (repairMode == "1") then
example code here...
elseif (repairMode == "2") then
example code here...
end


Ammako 12-14-17 12:39 PM

When making option menus and stuff I like to name the variables after what they are; in this case it would be repairModeRadioButton.
That way you guarantee that there will be no conflicts with accidentally naming two variables the same thing.

Maybe you can set some variables as local, too, but idk how Ace works and if it would allow it.

Smallinger 12-14-17 12:58 PM

Ok, thx for the tipp with the Variables names,

i test it a little bit an got a fix with
Code:

repairMode = {
        order        = 17,
        type        = "select",
        name    = "Repair mode",
        desc    = "",
        style        = "radio",
        values        = repairModeList,
        get          = function(info, value) return self.db.char.repairMode end,
        set          = function(info, value) self.db.char.repairMode = value end,
},



All times are GMT -6. The time now is 12:53 AM.

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