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:
local function UpdateExperience(self, event)
local bar = self.expBar
if not E.db.PCB.enabled or not E.db.PCB.experienceBar.progress then
bar.statusBar:SetStatusBarColor(0, 0.4, 1, 0.8) -- ElvUI default colour
return
end
local isMaxLevel = UnitLevel("player") == MAX_PLAYER_LEVEL_TABLE[GetExpansionLevel()]
if isMaxLevel and E.db.PCB.experienceBar.capped then
bar.text:SetText(L["Capped"])
elseif E.db.PCB.experienceBar.progress and not isMaxLevel and event == "PLAYER_XP_UPDATE" then
local avg = UnitXP("player")/UnitXPMax("player")
avg = PCB:Round(avg, 1)
bar.statusBar:SetStatusBarColor(0, 0, avg, 0.8)
end
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.