Thread Tools Display Modes
07-29-13, 05:15 AM   #1
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 331
Ace3Config - "multiselect" option group type

Can someone clarify how to properly address the Set and Get values I should be using?

The help section is a bit vague on how they go about addressing things:

multiselect

Basically multiple "toggle" elements condensed into a group of checkboxes, or something else that makes sense in the interface.

values (table|function) - [key]=value pair table to choose from, key is the value passed to "set", value is the string displayed
get (function|methodname) - will be called for every key in values with the key name as last parameter
set (function|methodname) - will be called with keyname, state as parameters
tristate (boolean) - Make the checkmarks tri-state. Values are cycled through unchecked (false), checked (true), greyed (nil) - in that order.
Here is my option section and the various functions and relations:
Lua Code:
  1. -- Values table
  2.  
  3. local cZones = {
  4.     ["none"] = "World",
  5.     ["arena"] = "Arena",
  6.     ["pvp"] = "Battleground",
  7.     ["party"] = "Instance",
  8.     ["raid"] = "Raid"
  9. }
  10.  
  11. -- Get and Set functions
  12.  
  13. local function GetValue(info)
  14.     local db = AAM.db.profile
  15.     if type(info.arg) == "table" then
  16.         return db[info.arg[1]][info.arg[2]]
  17.     else
  18.         return db[info.arg]
  19.     end
  20. end
  21.  
  22. local function SetValue(info,v)
  23.     local db = AAM.db.profile
  24.     if type(info.arg) == "table" then
  25.         db[info.arg[1]][info.arg[2]] = v
  26.     else
  27.         db[info.arg] = v
  28.     end
  29.     AAM:UpdateMarks()
  30. end
  31.  
  32. -- DB
  33.  
  34. local defaults = {
  35.     profile = {
  36.         enable = true,
  37.         activeLayout = "default",
  38.         zoneType = "ANY",
  39.         customZones = {
  40.             ["none"] = true,
  41.             ["arena"] = false,
  42.             ["pvp"] = false,
  43.             ["party"] = false,
  44.             ["raid"] = false
  45.         }
  46.     }
  47. }
  48.  
  49. -- Option table
  50. Zones = {
  51.     name = "Enabled Zones",
  52.     type = "multiselect",
  53.     disabled = function() if db.zoneType ~= "CUSTOM" or not db.enabled then return false end end,
  54.     values = cZones,
  55.     get = GetValue,
  56.     set = SetValue,
  57.     arg = "customZones",
  58. }

Basically it's dropping a string value into 'db.customZones' instead of indexing into the table and a boolean value.

Should I be using a string to table, table to string?'

EDIT: After trying to find another addon that uses this method (Omen in this case) I found that there is an extra parameter you can call as the 'keyname' that they state on the AceConfig help page I quoted.

get = function(info, k)
set = function(info, k, v)

Last edited by suicidalkatt : 07-29-13 at 05:29 AM.
  Reply With Quote
07-29-13, 05:08 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
The first parameter passed to any get/set function in an AceConfig table is always the info table, followed by any input-type-specific parameters, so:

get (function|methodname) - will be called for every key in values with the key name as last parameter
set (function|methodname) - will be called with keyname, state as parameters
... means that those functions work as follows:

Code:
get = function(info, key) --[[ do stuff ]] end
set = function(info, key, value) --[[ do stuff ]] end
This holds true for any other input types. If the docs say your get/set functions get value and "lolcats", then they get:

Code:
get = function(info) --[[ do stuff ]] end
set = function(info, value, "lolcats") --[[ do stuff ]] end
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
07-29-13, 08:16 PM   #3
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 331
Originally Posted by Phanx View Post
The first parameter passed to any get/set function in an AceConfig table is always the info table, followed by any input-type-specific parameters, so:



... means that those functions work as follows:

Code:
get = function(info, key) --[[ do stuff ]] end
set = function(info, key, value) --[[ do stuff ]] end
This holds true for any other input types. If the docs say your get/set functions get value and "lolcats", then they get:

Code:
get = function(info) --[[ do stuff ]] end
set = function(info, value, "lolcats") --[[ do stuff ]] end
Yea I had posted in my edit that I had found the solution. Thank you for your additional clarifications :3
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Ace3Config - "multiselect" option group type


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