View Single Post
05-14-13, 12:00 AM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Creating a new OnUpdate function every time you run the command is fairly wasteful. You should also use the elapsed value passed to your OnUpdate function, instead of calling GetTime() repeatedly.

Code:
local pull, seconds, onesec

local frame = CreateFrame("Frame")
frame:Hide()
frame:SetScript("OnUpdate", function(self, elapsed)
    onesec = onesec - elapsed
    pull = pull - elapsed
    if pull <= 0 then
        SendChatMessage("Pulling!", "RAID_WARNING")
        self:Hide()
    elseif onesec <= 0 then
        SendChatMessage(seconds, "RAID_WARNING")
        seconds = seconds - 1
        onesec = 1
    end
end)

SlashCmdList["COUNTDOWN"] = function(t)
    t = tonumber(t) or 6

    pull = t + 1
    seconds = t
    onesec = 1

    frame:Show()
end

SLASH_COUNTDOWN1 = "/inc"
__________________
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