06/19/23, 09:42 AM | #1 |
|
General saved variable questions
Hiya I have an addon with account wide saved variables but I'm looking to save 1 specific option as character specific.
Ive been trying different ways to format "the saving of" the variable to turn it into a sort of named table for each character that would save an ID number that would look something like this: Code:
MyAddonVars = { ["Default"] = { ["@MyUsername"] = { ["$AccountWide"] = { ["savedVariable"] = something,--<<<< the normal account wide variables ["savedVariable"] = something, ["savedVariable"] = something, ["savedVariable"] = something, ["charVariables"] = character1 = 10,--<<< table for each char saving a skill ID i need character2 = 12, character3 = 14, character4 = 16, I suppose the format below would be ok as well incase I wanted to save more to each character later.. { ["Default"] = { ["@MyUsername"] = { ["$AccountWide"] = { ["savedVariable"] = something,--<<<< the normal account wide variables ["savedVariable"] = something, ["savedVariable"] = something, ["savedVariable"] = something, ["character1"] = skillId = 10,--<<< this style would also work ["character2"] = skillId = 12, ["character3"] = skillId = 14, ["character4"] = skillId = 16, Code:
Myaddon.savedVariables.[charVariables].GetUnitName("player") = 10 or Myaddon.savedVariables.GetUnitName("player").skillId = 10 or even Myaddon.savedVariables.GetUnitName("player") = 10 is it possible to define 2 sets of variables in one file like account wide AND character name specific with these? Id prefer option 1 though if possible. Code:
MyAddon.savedVariables = ZO_SavedVars:NewAccountWide( MyAddon.svName, MyAddon.svVersion, nil, defaultSavedVars ) Last edited by sinnereso : 06/19/23 at 11:00 AM. |
06/19/23, 12:47 PM | #2 |
>Check Edit3, should be the easiest way!
First answer: Lua Code:
yourTableToSaveCharacterIdDataIn must be in your SVs defaults' table as empty table "defaultSavedVars" ! Else you will get an nil error. Where "characterIdOfYourToon" is the unique chracterId of the character you want to save the data for. You can get all characterIds of your account's characters as shown iny our other thread, where you wanted to know how to get the character names and ids of all toons of your account. See GetNumCharacters() and then loop from 1 to GetNumCharacters() and use GetCharacterInfo() to get the uniqueIds of each character at that index in the loop. And GetCurrentCharacterId() for the currently loged in characterId if you only need that. GetUnitName should not be used if this is about your current character as names can change! You should especially not use that names and strings in savedvars! Use the IDs which never change, as mentioned many times now. Edit btw this is completely wrong syntax Myaddon.savedVariables.[charVariables].GetUnitName("player") 1st Myaddon.savedVariables.[charVariables] cannot work. Either . or [key]! So either Myaddon.savedVariables[charVariables] or Myaddon.savedVariables.charVariables, but the latter does not work if charVariables is a variable, you need to use the [] then around it. The . syntax only works if the key of your table is a string, e.g. Myaddon.savedVariables.myTable1 is the same as Myaddon.savedVariables["myTable1"] 2nd Myaddon.savedVariables.[charVariables].GetUnitName("player") won't accept any API function CALLS directly fter a . ! You also need to put that into [] as the API function GetUnitName("player") returns a string! so: Myaddon.savedVariables[charVariables][GetUnitName("player")] and keep in mind that Myaddon.savedVariables[charVariables] mustbe defined as {} empty table somwhere to make it "exist", else you cannot fill it with [GetUnitName("player")] and you'd get a "try to index a nil value" -> means you try to put something inside a table but the table is nil (does not exist). index always points you to a table type! Edit2: In your txt manifest you have defined a ## SavedVariables table, e.g. MyAddonsSV. This is a global variable which is accessible. You can even change that directly without using ZO_SavedVars wrapper to reference it to MyAddon.savedVariables. So you could also change MyAddonsSV[GetDisplayName()[GetCurrentCharacterId()] = { subtable1 = { [key] = value, } } and read it from there too BUT: As you already use a ZO_SsavedVars wrapper keep using it and just update the reference MyAddon.savedVariables then with your subtable for the character dependent data. Edit3: You can also specify another 3rd parameter "profile" at the ZO_SavedVars wrapper: 1st account wide SVs MyAddon.savedVariables = ZO_SavedVars:NewAccountWide( MyAddon.svName, MyAddon.svVersion, nil, defaultSavedVars ) 2nd account wide character saved data: MyAddon.savedVariablesForCharacters = ZO_SavedVars:NewAccountWide( MyAddon.svName, MyAddon.svVersion, "CharacterData", defaultSavedVars ) Within your global SavedVariables table there will be created a subtable CharacterData then and you reference it via MyAddon.savedVariablesForCharacters instead of MyAddon.savedVariables then Last edited by Baertram : 06/19/23 at 01:31 PM. |
|
06/19/23, 06:18 PM | #3 |
|
these are litereally only temporary saved variables for use on each character that has has initiated the auto meticulous cp swap but not completed it before a reload or relog... once it completes on the correct character i intend to set the variable to nil which is why id like to avoid making a new file.
Im just trying to cover 4th base of thing that could happen. |
06/19/23, 08:30 PM | #4 |
|
THANK YOU BEAR!!! luvulongtime! that helped me soo much! I went with:
Code:
MyAddon.charVariables = ZO_SavedVars:NewAccountWide( MyAddon.svName, MyAddon.svVersion, GetUnitName("player"), nil ) and MyAddon.charVariables.autometSkill = something Last edited by sinnereso : 06/19/23 at 11:15 PM. |
06/20/23, 08:59 AM | #5 |
Yeah, you are welcome.
But !doh! I said "do not use NAMES" but IDs, as they are renamesave, and you use: "NAME"... Forgive me, but why? Instead of Code:
MyAddon.charVariables = ZO_SavedVars:NewAccountWide( MyAddon.svName, MyAddon.svVersion, GetUnitName("player"), nil ) Code:
MyAddon.charVariables = ZO_SavedVars:NewAccountWide( MyAddon.svName, MyAddon.svVersion, GetCurrentCharacterId(), nil ) |
|
06/20/23, 09:51 PM | #6 |
|
I know I know!!! The ID remain the same even after a namechange. I get it and does make sense but for the moment im happy with this so much and is easier to read in the files. Just being able todo this opens up many options ive been pondering for some time. Ill make note of the ID thing for now.
|
06/26/24, 08:05 PM | #7 |
|
Resurrecting my own thread for an additional queston related directly to the initial one...
if I were to need to iterate over the previously mentioned sub table in my saved variables how would I got about it? I've tried everything but at best have only been able to see a table and two functions but no data thats there.. Samples of what im working with below... Code:
--saved variable definition: RidinDirty.subtable = ZO_SavedVars:NewAccountWide( RidinDirty.svName, RidinDirty.svVersion, "some table", defaultSavedVars ) --which looks like this in the saved variable file: RidinDirtyVars = { ["Default"] = { ["@sinnereso"] = { ["$AccountWide"] = { ["travelOutside"] = true, ["apDeposit"] = true, ["bankALL"] = false, ["pvpDeaths"] = 2, ["some table"] = { [4487] = "item name1",--<< these are itemID as the key and item names as a text decription [43663] = "item name2", [533] = "item name3", im able to save and access them individually by itemid via: RidinDirty.subtable[itemId] = itemName somevariable = RidinDirty.subtable[itemId] what I'd like to be able to do is iterate over the entire subtable without previously knowing the keys/itemid's and print it to the chat window via something like: for i, v in pairs(RidinDirty.subtable) do--<< i used in pairs because the keys are itemID's and not sequential if i ~= nil then print(i, v) end end any suggestions? |
06/26/24, 08:17 PM | #8 |
RidinDirty.subtable = ZO_SavedVars:NewAccountWide( RidinDirty.svName, RidinDirty.svVersion, "some table", defaultSavedVars )
Lua Code:
The namespace param where you have used "some table" is not pointing to any table IN your savedvariables but it's the table "Default" which is ABOVE your savedvariables table, to structure it. Check the ZO_SavedVars wrapper description in ZOs code: https://github.com/esoui/esoui/blob/...edvars.lua#L11 So your pointer to the SV table, RidinDirty.subtable, actually points to nothing at the moment, just maybe an empty table where defaultSavedVars have been set to then. If you want to point to the correct table in your example you need to use: RidinDirty.subtable = ZO_SavedVars:NewAccountWide( RidinDirty.svName, RidinDirty.svVersion, nil, defaultSavedVars ) Either set the namespace to nil which will be replaced internally in ZO_SavedVars wrapper with "Default" then, or pass in "Default" yourself. After that you can iterate over RidinDirty.subtable and you should get all available data BELOW ["$AccountWide"], including the subtable ["some table"]. Or you directly use RidinDirty.subtable["some table"] Read more about SV here too: https://wiki.esoui.com/Storing_data_and_accessing_files And maybe use helper addons like merTorchbug ingame to inspect the SavedVars table /tb RidinDirtyVars to understand it's structure better and see current values. If you use ZO_SavedVars the table will always have some functions at the 1st level, GetInterfaceForCharacter and ResetToDefaults, which will be added by the ZO_SavedVars wrapper! default is your passed in table with the default values then -> defaultSavedVars Just click the __index in tbug inspector then to go on to the real table contents Last edited by Baertram : 06/26/24 at 08:25 PM. |
|
06/26/24, 08:23 PM | #9 | |
|
One last question.. there is a space in the table name. is that gonna be a problem? the table is named like "some table" with the itemid's and names inside it. Last edited by sinnereso : 06/26/24 at 08:26 PM. |
|
06/26/24, 08:42 PM | #10 |
Spaces in variables names are never a good idea
I guess it could work if you always use myTable["name here"] to access it but I actually never tried that -> I expect it to fail But myTable.name here definately would not work! |
|
06/26/24, 08:53 PM | #11 | |
|
I may need to reset the table for this and while I'm at it ill maybe remove the space as well. |
|
ESOUI » Developer Discussions » General Authoring Discussion » General saved variable questions |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|