Thread Tools Display Modes
Prev Previous Post   Next Post Next
05-15-14, 09:47 AM   #19
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
Originally Posted by Phanx View Post
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)
Thank You again Phanx. Works like a charm.

Coke.
  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » Count Down Timer


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off