View Single Post
05/16/23, 03:03 PM   #11
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,989
I showed you how to do that already in my 2nd last post where I showed you the fucntion to get the character names AND I also showed you how to build the choices (names to show in dropdown) AND choicesValues (characterIds to se in savedvariables) there?

So basically call the above function once with false -> returned table will be tab[characterId] = charName

local tab = GetCharactersOfAccount(false)
--Then loop over tab with
local choices = {}
local choicesValues = {}
local count = 0
for charId, charName in pairs(tab) do
count = count + 1
choices[count] = charName
choicesValues[count] = charId
end
Call that once before the LAM settings are created to create choices and choicesValues.
Then just pass in that choices and choicesValues table to the LAM dropdown, at the very same parameter names of the dropdown's data table.
If choicesValues is defined your setFunc will save those values (the characterId) to your SV then, instead of the names of choices. If choicesValues is nil it will just use the chocies entries (string characterName).

If you need a disabled entry just use table.insert(choices, 1, "Disabled") and table.insert(choicesValues, 1, -1) after choices and choicesValues have been fileld from tab (after the for...do ... end loop)
-1 is the disabled value then to save in the SVs.

I dunno how to describe that better without writing you the whole addon code, so this is up to you now

btw:
Disabled is a string that the game already translates so you can use the GetString(SI_*) function to get it localized already.
Check the localized strings here for the correct SI_* constant and search for "Disabled": and you'll find SI_CHECK_BUTTON_DISABLED
So use GetString(SI_CHECK_BUTTON_DISABLED) instead of a fixes string "Disabled" and you will have all supported languages based on the actual client language. As your choicesValues always returns -1 you just need to check for -1 instead of "Disabled" (which shouldn't be done at all, string comparison, if there is a way to use a dedicated number e.g.. Same like characterNames vs characerIds!)

Last edited by Baertram : 05/16/23 at 03:12 PM.
  Reply With Quote