View Single Post
06-15-20, 12:57 PM   #3
Adapt
A Murloc Raider
Join Date: Jun 2020
Posts: 6
Originally Posted by Ketho View Post
You need to wait until ADDON_LOADED until your savedvariables are available
https://wow.gamepedia.com/Saving_var..._game_sessions

...
Thanks for your kind help and quick response. Does this mean that any logic in relation to interacting with that variable needed to come after that event has fired?

i.e.

Lua Code:
  1. local Congrats_EventFrame = CreateFrame("Frame")
  2. local defaults = {
  3.     TotalXP = 0
  4. }
  5.  
  6. Congrats_EventFrame:RegisterEvent("ADDON_LOADED")
  7. Congrats_EventFrame:RegisterEvent("CHAT_MSG_COMBAT_XP_GAIN")
  8. Congrats_EventFrame:SetScript("OnEvent",
  9.     function(self, event, ...)
  10.         if event == "CHAT_MSG_COMBAT_XP_GAIN" then
  11.             local arg1 = ...
  12.             local xpgained = string.match(string.match(arg1, "%d+ experience"), "%d+")
  13.        
  14.             print('--xp gained--')
  15.             print(UnitLevel("player"), xpgained, date("%d/%m/%y %H:%M:%S"))
  16.             print('---')
  17.  
  18.             -- this doesn't seem to get saved or displayed?
  19.             XPLogger.TotalXP = XPLogger.TotalXP + tonumber(xpgained)
  20.             print('Total XP' .. XPLogger.TotalXP)
  21.         elseif event == "ADDON_LOADED" then
  22.             local addon = ...
  23.             if addon == "XPlogger" then
  24.                 print('XPLogger loaded')
  25.                 XPLogger = XPLogger or defaults
  26.                 self:UnregisterEvent(event)
  27.             end
  28.         end
  29.     end)
  Reply With Quote