I am writing a plugin for ElvUI, and yes, I could (and often do) ask Lua questions on their forums. However, this might be a universal question that is not unique to ElvUI.
In ElvUI there is a function that sets the text for the XP bar and I have securely hooked that function to alter the text and also colour the statusbar based on the average value of currentXP/maximumXP.
This so far is working splendidly. The text I set is working, and the new colour is working -- sort of. It does set the new colour, but I can't be 100% certain that the colour is dynamically updating.
Here is my code, which is called when Elv's function is hooked.
Lua Code:
local function UpdateExperience(self, event)
local bar = self.expBar
local isMaxLevel = UnitLevel("player") == MAX_PLAYER_LEVEL_TABLE[GetExpansionLevel()]
local text = ""
local current, maximum = EDB:GetXP("player")
local avg = current / maximum
avg = PCB:Round(avg, 2)
if isMaxLevel then
text = L["Capped"]
bar.text:SetText(text)
bar.statusBar:SetStatusBarColor(0, 0.4, 1, 0.8)
bar.rested:Hide()
else
bar.statusBar:SetStatusBarColor(0, 0.1, avg, 1)
end
end
Line 15 in this chunk is the one that concerns me. UpdateExperience() is called each time Elv's similar function is called, so you would think the value of avg would be updated, and thus the SetStatusBarColor() would also change. But I'm not confident, hence I am here.
ElvUI aside, this is otherwise a basic Lua question I think. Anyone writing status bar code might be interested, so here I am.
Do I need to hide the status bar, colour it, then show it again? Also, when the character is at maximum level the status bar colour is not a nice blue and instead is black or empty. Why would that occur?