Create a mini-timer using OnUpdate

This code will print ping! in ChatFrame1 every 2 seconds.

Snippet

local total = 0

local function onUpdate(self,elapsed)
    total = total + elapsed
    if total >= 2 then
        DEFAULT_CHAT_FRAME:AddMessage("ping!")
        total = 0
    end
end

local f = CreateFrame("frame")
f:SetScript("OnUpdate", onUpdate)
Posted by Mikma at Mon, 27 Apr 2009 10:46:12 +0000