Thread: Fading Textures
View Single Post
08-19-18, 11:57 AM   #25
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,934
Thanks for your insight Seerah,

Originally Posted by Seerah View Post
Line 4:
addonData will never be empty or nil (unless there is serious issue with the WoW client, in which case you have greater worries than just your addon)
I suspected that might be the case. I just couldn't remember if it started as nil or {} I just used my rule of programming practice, make sure an item exists before trying to use it, either initialise it by default or validate it exists before using

Originally Posted by Seerah View Post
This -is- what you want to do when initializing your saved variables table, however. If it already exists, you don't want to overwrite it with an empty table. This also means that you have to wait until your addon's variables load (or later) to see if they exist yet and to do something with them if they do.

Lua Code:
  1. local addonName, addonTable = ...
  2.  
  3. local version = GetAddonMetadata(addonName, "Version")
  4.  
  5. local f = CreateFrame("Frame")
  6. f:RegisterEvent("VARIABLES_LOADED")
  7. f:SetScript("OnEvent", function(self, event, arg1)
  8.           if event == "VARIABLES_LOADED" and arg1 = addonName then
  9.                PawDB = PawDB or {}
  10.                if not PawDB.version or PawDB.version ~= version then
  11.                     --show your splash screen
  12.                end
  13.                PawDB.version = version
  14.           end
  15.      end)
Oh, great catch on checking if the PawDB.version variable exists, especially if you start with an empty table, which I didn't deal with as normal I don't have empty tables, I usually have it initialised to default values so it is never non existent. A good alternative nonetheless, although, I have personally found that VARIABLES_LOADED isn't consistent, so I either use it as a check point ( in case it is called at the right time ) and/or use the PLAYER_LOGIN/PLAYER_ENTERING_WORLD ( when arg1 == true ) events ensuring that one doesn't overwrite the other. Each addon use varies depending on how and what it needs to do with the data.

Your placement of SavedVariable setting up may well be a better place if, the saved variable file contains a nil table, which would then overwrite the initialised table at the start of the file then it would cause a problem. However, the only time I think it would be nil is when you are first creating the addon with that particular table and testing the settings back and forth. Simply deleting the wtf will fix that problem and your users shouldn't ever have the problem. I would suppose individual projects would have their own way of dealing with this and similar scenarios. But definitely a good thing to point out the other way of setting them up.

Originally Posted by Seerah View Post
(PS - If you want to do something only when the player logs in and not whenever they see a loading screen, there are 2 ways to do that.
  1. use PLAYER_LOGIN instead of PLAYER_ENTERING_WORLD
  2. unregister the PLAYER_ENTERING_WORLD event when it is no longer needed
)
This was the defacto way of dealing with PLAYER_ENTERING_WORLD when there were no parameters, and is still okay to use. But with the new parameters (firstLogin, uiReload), new addons/rewrites could utilise the new parameters and have one event deal with both initializing and refreshing of the addon UI and data accordingly. Of course, the addon developer choice is still there
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote