Quantcast Another question about SavedVariables - ESOUI
Thread Tools Display Modes
07/25/18, 02:10 PM   #1
Dueydoodah
Join Date: Aug 2015
Posts: 6
Another question about SavedVariables

I don't seem to be able to find any info on saving both Accountwide and character variables. Is it possible to save both? For example, I want to save account wide variables for top and left screen coordinates, but I want to save different user text strings for each character. I'd like them to be saved into the same character construct, such as:

Code:
MySavedVariables =
{
    ["Default"] = 
    {
        ["@Dueydoodah"] = 
        {
            ["$AccountWide"] = 
            {
                ["version"] = 1,
                ["left"] = 8,
                ["top"] = 14,
            },
            ["Aramil Du'ron"] = 
            {
                ["MainSet"] = "Healer weapon set!",
                ["BackupSet"] = "Tank weapon set!",
                ["version"] = 1,
            },
        },
    },
}
  Reply With Quote
07/25/18, 02:33 PM   #2
Baertram
 
Baertram's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 1,768
Use two variables in your addon, like accData and charData. Assign them to the appropriate zoysavedvars:newaccountwide or :newuniquecharacterid (don't know the exact name anymore) functions.

The parameters of both function calls should use the same addon name as identifier but different table keys (parameter before the default values, after the version, which is most of the time nil but accepts a string). This will make the account wides e.g. not directly appear below AccountWide but your chosen settings table key.

Works fine for me. I'll first load the accountwide settings, check some code from them and then load char settings to local settings (if user chose to store it per char), or just will use the account wides if he chose to use them (and assign them to local settings then).
  Reply With Quote
07/25/18, 03:59 PM   #3
Dueydoodah
Join Date: Aug 2015
Posts: 6
Originally Posted by Baertram View Post
Use two variables in your addon, like accData and charData. Assign them to the appropriate zoysavedvars:newaccountwide or :newuniquecharacterid (don't know the exact name anymore) functions.

The parameters of both function calls should use the same addon name as identifier but different table keys (parameter before the default values, after the version, which is most of the time nil but accepts a string). This will make the account wides e.g. not directly appear below AccountWide but your chosen settings table key.

Works fine for me. I'll first load the accountwide settings, check some code from them and then load char settings to local settings (if user chose to store it per char), or just will use the account wides if he chose to use them (and assign them to local settings then).
Thank you. I'll give it a shot.
  Reply With Quote
07/26/18, 05:02 AM   #4
Baertram
 
Baertram's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 1,768
If you need example code look at FCO Craft Filter, file FCOCraftFilter.lua.
Search for "-- LOAD USER SETTINGS".
Below you'll find the account wide settings loaded first:
FCOCF.settingsVars.defaultSettings = ZO_SavedVars:NewAccountWide(addonVars.addonSavedVariablesName, 999, "SettingsForAll", defaultsSettings, nil)


"SettingsForAll" is the section where the savedvars will be saved in your file.

The last parameter "nil" above is he table key which is ["default"[ in the savedvars file if left nil.
You are able to use this for the ESO Server e.g. if you want to have different settings per each eso server (NA, EU, PTS).
GetWorldName() gives you the servername.


After this the read account wide settings are used to determine if the user chose to use accountWide settings or settings for each char (saveMode).

Just as an example.
  Reply With Quote
07/28/18, 12:34 AM   #5
Shadowfen
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 29
Another example of mixed account-wide and character saved variables would be in ThiefTools. I've got some options which are always character and some which are always account wide, and some which the user can choose between character and account wide (separately for each toon).

The reading of the SavedVars (in ThiefTools.lua) is in onLoaded and once both the accountwide and character options are read, the TT.setOptionsScope chooses for each option section which set of values is used, either character or AW (accountwide).

The SF.defaultMissing() function (called by setOptionsScope) is used to set default values inside the option tables because the ZO_SavedVars:NewAccountWide() and ZO_SavedVars:New() functions only applies the defaults for a sub table only if it is missing - it does not recurse to add in missing subtable values (say from an upgraded option set). SF.defaultMissing() will read through the tables looking for missing keys and adding them from the provided defaults - but leaving the already existing values alone.

Last edited by Shadowfen : 07/28/18 at 12:38 AM.
  Reply With Quote
07/28/18, 11:02 AM   #6
Dueydoodah
Join Date: Aug 2015
Posts: 6
These are awesome examples. Thank you both very much. This will definitely be useful.
  Reply With Quote

ESOUI » Developer Discussions » Tutorials & Other Helpful Info » Another question about SavedVariables

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