ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   In need of help with loading my other characters savedVars and saving them (https://www.esoui.com/forums/showthread.php?t=8160)

r4cken 11/30/18 04:34 AM

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?

Baertram 11/30/18 07:51 AM

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

r4cken 11/30/18 08:44 AM

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

Baertram 11/30/18 09:27 AM

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.)

r4cken 11/30/18 02:27 PM

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?

votan 11/30/18 03:27 PM

Quote:

Originally Posted by r4cken (Post 36560)
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


All times are GMT -6. The time now is 03:11 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI