Thread Tools Display Modes
06/19/23, 09:42 AM   #1
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 245
Question 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,
is there a way to format "the saving of" my variables to save & access that table that actually works? Currently using "Myaddon.savedVariables.XXXXXX to save the upper ones listed there. Like the equivalent of using something like:
Code:
Myaddon.savedVariables.[charVariables].GetUnitName("player") = 10
or
Myaddon.savedVariables.GetUnitName("player").skillId = 10
or even
Myaddon.savedVariables.GetUnitName("player") = 10
OR

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 )
I think I know its possible and how to create a second saved variable file that character specific but prefer that as a last option

Last edited by sinnereso : 06/19/23 at 11:00 AM.
  Reply With Quote
06/19/23, 12:47 PM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,989
>Check Edit3, should be the easiest way!


First answer:
Lua Code:
  1. MyAddon.savedVariables.yourTableToSaveCharacterIdDataIn[characterIdOfYourToon] = {
  2.  [key1] = value1,
  3.  [key2] = value2,
  4. }


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.
  Reply With Quote
06/19/23, 06:18 PM   #3
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 245
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.
  Reply With Quote
06/19/23, 08:30 PM   #4
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 245
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
and appears to be working perfectly.. I literally only had to add the top line and change the other variable references and BAM working perfectly but currently in further testing by others with more alts. I only ever made 1 toon. Im templar4lyfe

Last edited by sinnereso : 06/19/23 at 11:15 PM.
  Reply With Quote
06/20/23, 08:59 AM   #5
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,989
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 )
Simply use:
Code:
MyAddon.charVariables = ZO_SavedVars:NewAccountWide( MyAddon.svName, MyAddon.svVersion, GetCurrentCharacterId(), nil )
All was there
  Reply With Quote
06/20/23, 09:51 PM   #6
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 245
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.
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » General saved variable questions


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