View Single Post
05-12-14, 01:08 AM   #20
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
You're not using OnUpdate correctly. You're setting your "remaining" variable to 0 every time your script runs, and setting "sec" to 60, and then checking a variable named "secs" that isn't defined anywhere, and then checking if "remaining" and "secs" are not equal which (assuming the "sec" definition is actually meant to be "sec") will always pass because 0 will never be equal to 60 and those are the only values those variables can ever have, and you're not actually keeping track of how much time has elapsed at all.

Code:
-- This variable needs to be outside of the OnUpdate so it persists between executions:
local remaining = PROPOSAL_DURATION

f:SetScript("OnUpdate", function(self, elapsed) -- You need to know how much time has elapsed
	-- Deduct the elapsed time (since the last OnUpdate) from the total remaining time:
	remaining = remaining - elapsed

	local color = remaining > 20 and "20ff20" or remaining > 10 and "ffff00" or "ff0000"

	-- Use SetFormattedText here, and don't split the color code in the middle of the alpha value.
	text:SetFormattedText("Queue Expires in |cff%s%s|r", color, SecondsToTime(remaining))
end)

f:RegisterEvent("LFG_PROPOSAL_SHOW")
f:SetScript("OnEvent", function(self, event)
	if event == "LFG_PROPOSAL_SHOW" then
		-- Restart the timer:
		remaining = PROPOSAL_DURATION
		self:Show()
	else
		self:Hide()
	end
end)
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote