libaddonmenu dropdown listbox default display
Hey guys im looking for a way to get a dropdown listbox using libaddonmenu to display a saved variable on it when it is NOT dropped down but otherwise NOT have that variable as a choice.
The reason is I'm trying to avoid the "double listing" that happens when the saved variable happens to be one of the choices. If i remove it as a choice the dropdown is blank other than the choices. Any suggestions? heres what im messing with right now: Code:
{ |
create your choices with a predefined table, regardless of what your save variable is and you shoudnt have the problem you are talking about
|
Your choices will be build once as the dropdown is created, as the menus opens.
If you want to update that later one, after changing the dropdown's selected entry, you need to update that table and re-assign it via dropdown:UpdateChoices(choices, choicesValues, choicesTooltips) function. Provide a reference to your LAM dropdwn so you can access it after it was created, e.g.in your data table of that dropdown add reference = "MyAddon_LAM_Dropdown1", Then crete a small fucntion e.g. Code:
local function updateMyChoices() Something like that. This is only needed if your dropdown choices should cange based on the SV you change via that dropdown, so take care what you reference! e.g. do not reference the SAME SV variable in teh choices directly which you change via the same dropdown! |
Another option I could work with might be to retrieve a list of all characters on the account and list them there but I'm not yet certain its possible.. Still digging.
|
IF you retrieve a list of characters from a saved variables file then you have the list.
CharacterA CharacterB CharacterC then you register the LAM options. Once you do that the table is set, the choices are set, and LAM knows how to populate the dropdown. You are trying to dynamically change the choices after registering the LAM menu. |
I like the idea of making a list in saved variables. Is it possible to create a table of character names manually in my accountwide variables?
something like: MyAddon.savedVariables.charNames = GetUnitName("player") but add to a table instead of just replacing the value? Ive never created a table this way and cant seem to wrap my head around how to do it. |
Lua Code:
Use table with the charname as choices (shows the names of the char as dropdown entries in the LAM dropdown) AND IMPORTANT: build your choicesValues table which uses the internal characterId then as key, and not the name as the name can be changed but characterId is unique (stays the same after rename) per server. So basically call the above function once with false -> returned table will be tab[characterId] = charName 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 Else you will get into trouble like always when you depend on translatable or changeable strings! |
TY. That looks like its to retrieve the charName from the saved variables? How do I save them there though? Or is that always done automatically already when they log in with account wide variables? I only ever made 1 toon so I never noticed this.
|
It does not read anything from savedvariables, it's reading it via API functions from your account. No SV needed for that.
What do you want to save in the SV? All the characternames and ids? Not needed as they do not change and the function can determine them on the fly quickly. Just call that ONCE at start of your addon and keep them local in your addon data, not in the sv. e.g. MyAddon.characterData = GetCharactersOfAccount(false) If you need the characterId or name then just access your MyAddon.characterData table. Or build yourself a lookup tbale like described above with the choices and choicesValues example for the LAM dropdown! Example for LAM dropdown "Choose a character": Follow my example how to build the choices and choicesValues above, last post! And then use the characterId returned by choicesValues, via the LAM dropdown -> selected entry will use the choicesValues characterId and pass it to the setFunc of your dropdown -> save the selected characterId to the SV that way via the setFunc as normal LAM settings work. General character dependent SavedVariables (if your addon should save per char and not per account): If you want to save data BELOW your characterId in the SavedVariables you need to use another ZO_SavedVars: wrapper like NewCharacterIdSettings instead of New or NewAccountWide, but this will save your total SavedVars character dependent and not account dependent then. The WIKI explains more, search there please. If this all does not help please explain what exactly you want to achieve here, and if you use a LAM dropdown and what it should show as entries, and what should happen then if you change that dropdown entries etc. Make a simple example and describe in simple steps, and then we will find a simple way (or not ;-) ). |
I appreciate all the help.
Im looking to build a list of all character names on account ONLY for one LAM dropdown panel, otherwise am perfectly happy with a NewAccountWide settings in my variables. The purpose is to be able to select ONE of them in the list to NOT auto deposit. Like a main character sort of thing. The rest of my LAM dropdown works perfectly I just need to get a list of names into it for the "CHOICES". **EDIT I realize ID's are the preferred method due to them being compatible with name changes etc but NAMES is fine for my needs. Its not a critical feature and it can be changed/updated from any character if a name change does happen. That function looks pretty clear but how do I get that data into the LAM control HERE: Code:
{ |
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?
Quote:
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!) |
tables kill me everytime. I cant seem to vizualize the flow with these things.
|
Not sure what exactly you mean?
tables are quite easy. They are defined via = {} and in there is a key = value, pair. key can be string like "hello" or a number like [1] or even a control or another table or some pointer to another variable, and value can be about the same :) -> That's the only challenging part here that a table could contain other tables. tables with non-gap numbers like [1] = "a", [2] = "b", [3] = "c", can be iterated via ipairs function (in defined order 1 to n (here 3)). And tables with a gap number, or a non-number key like [1] = "a", [3] = "c", or ["a"] = "a", ["b"] = "b", ["c"] = "c", can be iterated via the pairs function (attention: Will iterate keys in random order! each time) in lua about everything uses tables so you should get comfortable with these ;-) https://wiki.esoui.com/LUA_Tables |
yeh ive been over that 1000 times.. guess i need another 1000 =p
**EDIT I got it working finally! Thank you all for the help |
All times are GMT -6. The time now is 05:12 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI