View Single Post
09-18-17, 02:57 PM   #9
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
The bug as it turns out, was with my use of the print() statement, and not with how I used ElvUI's returns.
Code:
print("The average XP is ", avg)
I did switch to UnitXP("player") and UnitXPMax("player") although there was nothing wrong with Elv' returns; I just didn't need to check for pet XP.

About the nested if/then stuff, maybe it can be cleaned up, but it works now, and I have more modules to write. Maybe one day I will look at it and refactor the code.
Lua Code:
  1. local function UpdateExperience(self, event)
  2.     local bar = self.expBar
  3.     if not E.db.PCB.enabled or not E.db.PCB.experienceBar.progress then
  4.         bar.statusBar:SetStatusBarColor(0, 0.4, 1, 0.8) -- ElvUI default colour
  5.         return
  6.     end
  7.  
  8.     local isMaxLevel = UnitLevel("player") == MAX_PLAYER_LEVEL_TABLE[GetExpansionLevel()]
  9.  
  10.     if isMaxLevel and E.db.PCB.experienceBar.capped then
  11.         bar.text:SetText(L["Capped"])
  12.     elseif E.db.PCB.experienceBar.progress and not isMaxLevel and event == "PLAYER_XP_UPDATE" then
  13.         local avg = UnitXP("player")/UnitXPMax("player")
  14.         avg = PCB:Round(avg, 1)
  15.         bar.statusBar:SetStatusBarColor(0, 0, avg, 0.8)
  16.     end
  17. end

I will say that it looks very snazzy. I took my level 1 bank alt out and smacked around some boars and wolves until level 7. Much better than the default XP bar colours of ElvUI.
  Reply With Quote