Thread Tools Display Modes
07/18/23, 10:17 AM   #1
NeuroticPixels
Addon Addict
 
NeuroticPixels's Avatar
Premium Member
Join Date: May 2019
Posts: 211
Unhappy Change to account-wide settings? (ResourceRadar)

Hi.
I looked through https://www.esoui.com/forums/showthread.php?p=41611 to see if I could figure out how to edit a lua to make it use account-wide settings.

I couldn't figure it out. I tried and failed. Received an error upon logging in to ESO.

I have this saved as a reminder:



But..... I've never seen an addon use this before:

Code:
    ResourceRadar_SavedVars = ResourceRadar_SavedVars or {}
    local characterId = GetCurrentCharacterId()
    ResourceRadar_SavedVars.character = ResourceRadar_SavedVars.character or {}
    ResourceRadar_SavedVars.character[characterId] = ResourceRadar_SavedVars.character[characterId] or {}
    self.currentProfile = ResourceRadar_SavedVars.character[characterId]
    
    self:InitializeDefaults()
The addon (ResourceRadar) currently doesn't save any settings that I set from one character to the next. I'd like the settings to be account-wide.

I tried looking at the Saved Variables to see if I could edit those. But it seems to be missing the line for my character name, so I don't know how to add that. I don't know if everything has to be indented properly.... I don't know where exactly to put brackets... ugh.

This is what the saved variables currently say:

Code:
ResourceRadar_SavedVars =
{
    ["character"] = 
    {
        ["8796093035941557"] = 
        {
            ["worldPinPulse"] = false,
            ["displayNodesInWorld"] = true,
            ["compassPinSize"] = 20,
            ["displayNodesOnMap"] = false,
            ["worldPinSize"] = 66,
            ["displayNodesOnCompass"] = false,
            ["removeOnDetection"] = 
            {
                [1] = false,
                [2] = false,
                [3] = false,
                [4] = false,
                [5] = false,
                [6] = false,
                [7] = false,
                [8] = false,
                [9] = false,
                [100] = false,
            },
            ["mapPinSize"] = 16,
            ["worldPinTexture"] = "esoui/art/ava/ava_rankicon64_centurion.dds",
            ["pinTextures"] = 
            {
                [1] = "esoui/art/crafting/smithing_tabicon_refine_down.dds",
                [2] = "esoui/art/icons/servicemappins/servicepin_clothier.dds",
                [3] = "esoui/art/icons/mapkey/mapkey_lumbermill.dds",
                [4] = "esoui/art/crafting/enchantment_tabicon_essence_down.dds",
                [5] = "esoui/art/crafting/alchemy_tabicon_reagent_down.dds",
                [6] = "esoui/art/icons/servicemappins/servicepin_dyestation.dds",
                [7] = "ResourceRadar/Textures/waterplant.dds",
                [8] = "esoui/art/treeicons/store_indexicon_consumables_down.dds",
                [9] = "esoui/art/icons/servicemappins/servicepin_alchemy.dds",
                [100] = "esoui/art/icons/poi/poi_crafting_complete.dds",
            },
            ["pinColors"] = 
            {
                [1] = 
                {
                    [4] = 1,
                    [1] = 0.4470000000,
                    [2] = 0.4900000000,
                    [3] = 1,
                },
                [2] = 
                {
                    [4] = 1,
                    [1] = 0.5880000000,
                    [2] = 0.9880000000,
                    [3] = 1,
                },
                [3] = 
                {
                    [4] = 1,
                    [1] = 1,
                    [2] = 0.6940000000,
                    [3] = 0.4940000000,
                },
                [4] = 
                {
                    [4] = 1,
                    [1] = 1,
                    [2] = 0.4550000000,
                    [3] = 0.4780000000,
                },
                [5] = 
                {
                    [4] = 1,
                    [1] = 0.4510000000,
                    [2] = 0.5690000000,
                    [3] = 0.4240000000,
                },
                [6] = 
                {
                    [4] = 1,
                    [1] = 0.5570000000,
                    [2] = 1,
                    [3] = 0.5410000000,
                },
                [7] = 
                {
                    [4] = 1,
                    [1] = 0.4390000000,
                    [2] = 0.9370000000,
                    [3] = 0.8080000000,
                },
                [8] = 
                {
                    [4] = 1,
                    [1] = 0.5690000000,
                    [2] = 0.8270000000,
                    [3] = 1,
                },
                [9] = 
                {
                    [4] = 1,
                    [1] = 0.9340000000,
                    [2] = 0.3450000000,
                    [3] = 0.5370000000,
                },
                [100] = 
                {
                    [4] = 1,
                    [1] = 1,
                    [2] = 0.0117647061,
                    [3] = 0,
                },
            },
        },
    },
}
Would I just change ["character"] to ["default'] and ["8796093035941557"] to [$AccountWide]?
I figured I needed to put in the account name between those. (["@NeuroticPixels"]). But I don't know about all the indents for each line and how to connect the brackets.
I've only ever edited what's in a saved vars. I've never had to add any new lines.

I apologize for my ignorance. Please be gentle with me.

Last edited by NeuroticPixels : 07/18/23 at 10:21 AM.
  Reply With Quote
07/18/23, 10:34 AM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,989
Seems the addon is not using the ZO_SavedVars wrapper for accessing the SV table ResourceRadar_SavedVars.
-> The wrapper is creating the subtables ["default'] and [$AccountWide] e.g. so they are missing because ZO_SavedVars was not used!

Exaplanation:
SavedVars defined as ## SavedVariables in the addon's txt file are just a global table.
So ResourceRadar_SavedVars is a table.
And the addon decided to add the structures like the characterId etc. "manually" to that table instead of using the Zos wrapper for that, called "ZO_SavedVars".

If you want to change the addon's SV table from characterId to accountWide you need to replace each occurence of characterId in there with your accountName (API function: GetDisplayName())

This applies to the code you had copied here, but also to the settings menu and every other file and code where ResourceRadar_SavedVars is currently used with the .character[characterId].

I'd keep the .character subtable in the SV table ResourceRadar_SavedVars, and just add a new subtable .account.
That way you could switch back to characterId SV later. See further down below!

Code now:
Lua Code:
  1. ResourceRadar_SavedVars = ResourceRadar_SavedVars or {}
  2.     local characterId = GetCurrentCharacterId()
  3.     ResourceRadar_SavedVars.character = ResourceRadar_SavedVars.character or {}
  4.     ResourceRadar_SavedVars.character[characterId] = ResourceRadar_SavedVars.character[characterId] or {}
  5.     self.currentProfile = ResourceRadar_SavedVars.character[characterId]


Could be changed to:
Lua Code:
  1. ResourceRadar_SavedVars = ResourceRadar_SavedVars or {}
  2.     local characterId = GetCurrentCharacterId()
  3.     ResourceRadar_SavedVars.character = ResourceRadar_SavedVars.character or {}
  4.     ResourceRadar_SavedVars.character[characterId] = ResourceRadar_SavedVars.character[characterId] or {}
  5.     --self.currentProfile = ResourceRadar_SavedVars.character[characterId] --Commented as the currentProfile should be used from account data now, see below!
  6.  
  7.     local currentAccount = GetDisplayName()
  8.     ResourceRadar_SavedVars.account = ResourceRadar_SavedVars.account  or {} --reuses the account subtable or creates an empty one if missing
  9.     ResourceRadar_SavedVars.account[currentAccount] = ResourceRadar_SavedVars.account[currentAccount] or {}
  10.     self.currentProfile = ResourceRadar_SavedVars.account[currentAccount ]


And after that you need to find EACH code line where currently ResourceRadar_SavedVars.character[characterIdHere] is used and replace it with
ResourceRadar_SavedVars.account[GetDisplayName()] so that the SV table will be read from your account data now.

After 1st login and 1x /reloadui ingame., with that changed SV data subtable .account, you should see the .account table in the SV file in your live/SavedVariables/<addonFolderName>.lua file.

And you can logout then, backup the file and manually copy over your character entry of 1 of your characters to the account["@YourAccountNameHere"] table.



If you have kept the .character subtables:
You could even add a settings menu entry to switch that dynamically via the LibAddonMenu settings.
Like always read the account SV first and if there is saved something like a boolean (true/false) variable savePerCharacter you can switch the SV usage with it.
-> Checkbox in LAM settings of the addon should change ResourceRadar_SavedVars.account[currentAccount].savePerCharacter via it's setFunc and read the same via the getFunc.

At the SV initialization you can read it explicitly then and switch the SV usage:
Lua Code:
  1. local sv -- define that at the top of the file so it's accessible properly within all functions and within the LibAddonMenu settings
  2.  
  3. --In the EVENT_AD_ON_LOADED callback function:
  4. if ResourceRadar_SavedVars.account[currentAccount].savePerCharacter == true then
  5.  --Use character SavedVars
  6.    sv = ResourceRadar_SavedVars.character[GetCurrentCharacterId()]
  7. else
  8.   --Use account savedVars
  9.    sv = ResourceRadar_SavedVars.account[GetDisplayName()]
  10. end

You'd have to change the hardcoded usage of ResourceRadar_SavedVars.account or ResourceRadar_SavedVars.character to use the "sv" variable then, as it will "reference" then either the character or the account SV subtable for your saved data, for reading and writing.

Last edited by Baertram : 07/18/23 at 10:41 AM.
  Reply With Quote
07/18/23, 12:12 PM   #3
NeuroticPixels
Addon Addict
 
NeuroticPixels's Avatar
Premium Member
Join Date: May 2019
Posts: 211
Thank yoooou! You are a king, good sir!
  Reply With Quote

ESOUI » AddOns » AddOn Help/Support » Change to account-wide settings? (ResourceRadar)


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