View Single Post
11/30/18, 07:51 AM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,966
Before trying to invent the wheel new you may look at this library first:
https://www.esoui.com/downloads/info...SavedVars.html


And this is how SavedVariables work in ESO standard, without a library[
The savedvars are bothing else then a global table with the name you specify in your addon's txt file.
You can access this table directly and change the entries in there.

ZO_SavedVars is only a helper function to assign a "pointer variable" (like myAddonSettings) to this global variable.

Example
You have specified your savedvariables object to be named like this in your addon.txt (manifest) file:
Code:
##SavedVariables: MyAddon_SV
If you want to change the SavedVariables of any character, you can achieve it like this:
I assume you are using server dependent SavedVariables.
-> If not, just strip the first [GetWorldName()] bracket!

Lua Code:
  1. local mySavedVariablesOfCharacterId = MyAddon_SV[GetWorldName()]["Default"][GetDisplayName()][CharacterId]

mySavedVariablesOfCharacterId will have additional contents which you have specified using ZO_SavedVars:Newxxx(). e.g. if you have specified ZO_SavedVars:NewCharacterIdSettings() to use a subtable "settings" you'll have this entry within mySavedVariablesOfCharacterId as well:
mySavedVariablesOfCharacterId["settings"].

[CharacterId] will be the uniqueId of your character.
You can get a list of them like this:

Lua Code:
  1. local chars = {}
  2.  
  3. local function getCharsOfAccount()
  4.  
  5.     --Get the char name and unique ID for the savedvars
  6.         for i = 1, GetNumCharacters() do
  7.             --Get name and unique id
  8.             --- @return name string,gender [Gender|#Gender],level integer,classId integer,raceId integer,alliance [Alliance|#Alliance],id string,locationId integer
  9.             local charName, _, _, classId, _, _, characterId, _ = GetCharacterInfo(i)
  10.             --Format the name
  11.             charName = zo_strformat(SI_UNIT_NAME, charName)
  12.             local charData = {}
  13.             charData.id         = characterId
  14.             charData.name       = charName
  15.             charData.nameClean  = charName
  16.             charData.class      = classId
  17.             chars[characterId] = charData
  18.  
  19.     end
  20. end

If you are using AccountWide SavedvAriables the CharacterId will be a fixed string "$AccountWide".


Additional information about SavedVars:
https://wiki.esoui.com/Circonians_Sa...ables_Tutorial
https://wiki.esoui.com/AddOn_Quick_Questions
https://wiki.esoui.com/Addon_manifest_(.txt)_format
https://www.esoui.com/forums/showthr...SavedVariables

Last edited by Baertram : 11/30/18 at 07:57 AM.
  Reply With Quote