Quantcast In need of help with loading my other characters savedVars and saving them - ESOUI
Thread Tools Display Modes
11/30/18, 04:34 AM   #1
r4cken
 
r4cken's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2018
Posts: 13
In need of help with loading my other characters savedVars and saving them

So i'm developing my addon Autobanker and i was thinking that it would be nice to have a
dropdown menu where i can select each character and change their settings without having to log in to each character and set them through the settings menu.

My problem, or dilemma i should say is that i want to be able to do something like

Code:
local function OnDropDownSelect(choice)
  UseSavedVarsFromCharacter(choice)
  -- Now any changes to AB.savedVars will alter the data for the selected character
end

local function DoSomethingToCharacterSavedVars(data)
  AB.savedVars.sometable = data
  -- Changed something in another characters settings.
end

local function SaveCharacterSavedVars()
 --???????
 --???????
 --???????
end

local function UseSavedVarsFromCharacter(characterId)
  AB.savedVars = AB.savedVars["Default"][GetDisplayName()][characterId]
end

local function Initialize(event, addon)
  -- Stripped non important parts here
  AB.savedVars = ZO_SavedVars:NewCharacterIdSettings("AutobankerSavedVars", 4, nil, defaults)
end
My initial thought was that maybe i could call ZO_SavedVars:NewCharacterIdSettings but i realised that it uses GetCurrentCharacterId() to do the actual book-keeping and saving to disk. So i have no idea how i can save the AB.savedVars back to disk for the other character's settings i changed.

Would it work to use a accountwide savedVars and change the different characters settings in that table?
__________________
Addon creator, programmer and gamer girl
  Reply With Quote
11/30/18, 07:51 AM   #2
Baertram
 
Baertram's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 2,413
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
11/30/18, 08:44 AM   #3
r4cken
 
r4cken's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2018
Posts: 13
Thank you so much! This cleared up lots for me. So if I understood you right, after I grab the table for the character i want to modify. If I change itís data itís going to be saved just as usual? It should because itís stored in the savedVars variable right?

That library seemed pretty nice! I think I know how to move forward now! I really appreciate the help
__________________
Addon creator, programmer and gamer girl
  Reply With Quote
11/30/18, 09:27 AM   #4
Baertram
 
Baertram's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 2,413
Found another good forum thread about different ways to save the SavedVars:
https://www.esoui.com/forums/showthr...=SavedVariable

Back to your question
Yes, after getting the SavedVars table of any character you can modify the contents just as modifying other table contents too.

Changing it will not be stored on the harddrive though until you do a reloadui or logout, just as normal SavedVariables as well (if you are not using the prioritized but randomized SV saving method for small data which was newly added with Murkmire to support saving of real important changes without reloadui.)
  Reply With Quote
11/30/18, 02:27 PM   #5
r4cken
 
r4cken's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2018
Posts: 13
Right, yes its only in memory before the reloadui or logout/login. But i should be able to edit all the characters i want one after eachother and not having to reloadui in between everyone?
__________________
Addon creator, programmer and gamer girl
  Reply With Quote
11/30/18, 03:27 PM   #6
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 496
Originally Posted by r4cken View Post
Right, yes its only in memory before the reloadui or logout/login. But i should be able to edit all the characters i want one after eachother and not having to reloadui in between everyone?
You get all your ids with:
Lua Code:
  1. for i = 1, GetNumCharacters() do
  2.   local _, _, _, _, _, _, id = GetCharacterInfo(i)
  3. ...
  4. end
__________________
@votan73 (EU - megaserver)
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » In need of help with loading my other characters savedVars and saving them

Thread Tools
Display Modes

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