ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Tutorials & Other Helpful Info (https://www.esoui.com/forums/forumdisplay.php?f=172)
-   -   Another question about SavedVariables (https://www.esoui.com/forums/showthread.php?t=7953)

Dueydoodah 07/25/18 02:10 PM

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,
            },
        },
    },
}


Baertram 07/25/18 02:33 PM

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

Dueydoodah 07/25/18 03:59 PM

Quote:

Originally Posted by Baertram (Post 35428)
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.

Baertram 07/26/18 05:02 AM

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.

Shadowfen 07/28/18 12:34 AM

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.

Dueydoodah 07/28/18 11:02 AM

These are awesome examples. Thank you both very much. This will definitely be useful.


All times are GMT -6. The time now is 07:50 AM.

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