As merlight said ZO_DeeptableCopy doen't copy metatables. Just copy from/to _G instead of trying to copy SimpleXPBar.AWSV or SimpleXPBar.CharSV
and you don't need SimpleXPBar.accountwide_settings, you can use SimpleXPBar.AWSV
Warning: Spoiler
Lua Code:
local function OnAddOnLoaded(event, addonName)
if addonName ~= ADDON_NAME then return end
local defaultsA = { }
local defaults = { }
TestAddon.svt = {}
TestAddon.sva = ZO_SavedVars:NewAccountWide("TestAddonSavedVars", 2, nil, defaultsA)
TestAddon.svc = ZO_SavedVars:New("TestAddonSavedVars", 2, nil, defaults)
TestAddon:LoadSavedVars(TestAddon.sva.accountWide)
TestAddon.CreateSettingsMenu(TestAddon)
EVENT_MANAGER:UnregisterForEvent(ADDON_NAME, EVENT_ADD_ON_LOADED)
end
--[[
You don't need to do a copy here, only copy in the settins menu
when the user toggles from accountWide to Char, that way
they get the most up-to-date version of the accountWide
saved vars and it doesn't run copies anymore than necessary
--]]
function TestAddon:LoadSavedVars(useAccountWide)
if useAccountWide then
TestAddon.svt = TestAddon.sva
else
TestAddon.svt = TestAddon.svc
end
end
[1] = {
type = "checkbox",
name = "Use Account Wide Settings",
default = true,
getFunc = function() return TestAddon.svt.accountWide end,
setFunc = function(bValue)
TestAddon.sva.accountWide = bValue
if not bValue then
local sDisplayName = GetDisplayName()
local sUnitName = GetUnitName("player")
-- TestAddonSavedVars = your addons saved var table name
-- from your manifest
ZO_DeepTableCopy(_G["TestAddonSavedVars"]["Default"][sDisplayName]["$AccountWide"], _G["TestAddonSavedVars"]["Default"][sDisplayName][sUnitName])
end
self:LoadSavedVars(bValue)
end,
},