View Single Post
05/01/14, 11:39 AM   #17
Wykkyd
Are you Wykkyd Gaming?
 
Wykkyd's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 107
You guys may or may not be aware of this so I'm sharing it here, because it seems appropriate:

The ZO_SavedVariables inserts and retrieves saved data from inside of an @Accountname sub table. If your user is on the Overflow server, or if your user is experiencing issues with the game client, or if they disable Guild & Friend features for maintenance or a hotfix (which they have done nearly once per week since launch)... your user will fail to load their saved variables as the active account the game client will be loading them under will be the value: ""

For this reason, and to support a feature I'm planning to add to my addons, I have CHANGED GEARS and am using my OWN character-name tabling of saved variable data without using ZO_SavedVariables.

## SavedVariables: mySaves

^^ that kind of line in your .txt file.

Then I basically just do the following on startup:

local defaults = {
var1 = "",
var2 = true,
var3 = 3,
}
local charName = GetUnitName( "player" )
if not mySaves then mySaves = {} end
if not mySaves[ savedVariableVersionNumber] then mySaves[ savedVariableVersionNumber] = {} end
if not mySaves[ savedVariableVersionNumber][ "global" ] then mySaves[ savedVariableVersionNumber][ "global" ] = defaults end
if not mySaves[ savedVariableVersionNumber][ charName ] then mySaves[ savedVariableVersionNumber][ charName ] = defaults end
myAddonGlobal.Settings = mySaves[ savedVariableVersionNumber][ charName ]
myAddonGlobal.GlobalSettings = mySaves[ savedVariableVersionNumber][ "global" ]


That's it. LOOKS more complex than it is. It's fairly simple, really. Still partitions saved variables by version and toon but doesn't include the account name (which is pointless at this point anyway) or any profile name (which you could easily add if you wished).

To read settings out I have a GetOrDefault method like:

myAddonGlobal.GetOrDefault = function( default, varToCheck ) if varToCheck == nil then return default else return varToCheck end end

And then I consume that like this:

control:SetWidth( myAddonGlobal.GetOrDefault( 250, myAddonGlobal.Settings[ "control width" ] ) )

And if you change the value of myAddonGlobal.Settings[ "control width" ] it does indeed save down to the SavedVariables file just as you should expect... automatically.


Basically this cleans up saved variable usage while at the same time CODING AROUND a relatively hurtful (to the user experience) game bug.



EDIT: This is the process I am shifting to with my suite-wide rewrite & overhaul. You won't find examples in my currently published addons, as of 5/1/2014. My overhaul is about halfway done and after that these kind of changes will be "live" and you'll be able to see them in action.
  Reply With Quote