Quantcast
WoWInterface - View Single Post - Logging all XP gains
View Single Post
06-15-20, 10:20 AM   #1
Adapt
A Murloc Raider
Join Date: Jun 2020
Posts: 6
Post Logging all XP gains

Hi all,
I am making a small addon for Classic that logs all XP gains to a SavedVariables file that I can then parse later for analysis. I am struggling a bit with the SavedVariables piece. Hoping someone can help.

XPlogger.toc
Lua Code:
  1. ## Interface: 11303
  2. ## Title: XPLogger
  3. ## Author: eightfive labs
  4. ## Notes: Logs all XP gains to a file for analysis later
  5. ## Version: 0.0.1
  6. ## SavedVariablesPerCharacter: XPLogger
  7.  
  8. main.lua

main.lua
Lua Code:
  1. local Congrats_EventFrame = CreateFrame("Frame")
  2. local defaults = {
  3.     TotalXP = 0
  4. }
  5.  
  6. XPLogger = XPLogger or defaults
  7. Congrats_EventFrame:RegisterEvent("CHAT_MSG_COMBAT_XP_GAIN")
  8. Congrats_EventFrame:SetScript("OnEvent",
  9.     function(self, event, ...)
  10.         local arg1 = ...
  11.         local xpgained = string.match(string.match(arg1, "%d+ experience"), "%d+")
  12.        
  13.         print('--xp gained--')
  14.         print(UnitLevel("player"), xpgained, date("%d/%m/%y %H:%M:%S"))
  15.         print('---')
  16.         XPLogger.TotalXP = XPLogger.TotalXP + tonumber(xpgained)
  17.         print('Total XP' .. XPLogger.TotalXP)
  18.     end)

However, I am not seeing the SavedVariables file being written and the XPLogger.TotalXP is reset on /reload.

Any help would be appreciated.
  Reply With Quote