Get an Epic Experience with Premium

WaitTimer

Libraries Login to Add Favorites
  • 0 Likes
  • Runes of Magic
  • 14 Monthly Downloads
  • Supports: 5.0.1
  • 717 Total Downloads
  • Updated 10/16/2012
  • Created 02/06/2012
  • 0 Favorites
  • Project Site
  • Comments
  • Release Type: Release
  • License: MIT License
  • Newest File: v1.5
or

About WaitTimer

This small library provides an easy way to generate timed events.

You can setup a delayed or repeated function call without messing around with a dummy frame and OnUpdate events.

Example:

-- a delayed function call
WaitTimer.Wait(5, function () DEFAULT_CHAT_FRAME:AddMessage("huhu") end)

-- repeated call (single timer)
WaitTimer.Wait(10, function ()
                  DEFAULT_CHAT_FRAME:AddMessage("wake up")
                  return 10
                end,
                 "mytimer") -- NB: "mytimer" must be a unique name
...
WaitTimer.Stop("mytimer")

-- repeated call
id = WaitTimer.Wait(10, function ()
                  DEFAULT_CHAT_FRAME:AddMessage("wake up")
                  return 10
                end)
...
WaitTimer.Stop(id)

-- with user data
function MyTimer(data) DEFAULT_CHAT_FRAME:AddMessage(data) end
WaitTimer.Wait(5, MyTimer, nil, "Hello World")

Setup:

copy theses files to your addon or any subdirectory of it

  • LibStub.lua
  • WaitTimer.lua

Usually people will use a "lib" subdirectory

Add them at the beginning of your .toc file to make sure they get loaded.

Init:

local WaitTimer = LibStub("WaitTimer")

put it at the beginnig of your lua file where you want to use the WaitTimer.

Usage:

timer_id = WaitTimer.Wait(seconds, function, id, data)
  • seconds= how long to wait
  • function= will be called when time is elapsed
    if the function returns a value, this value is used as new wait_time.
  • id= (optional) a fixed timer id If another timer with the same ID exists it will be replaced
  • data= (optional) will be passed to the function call
  • timer_id= id which can be used in the other functions It's equal "id" when it was provided

WaitTimer.Stop(id)
  • stops the timer without calling the function

waittime = WaitTimer.Remaining(id)
  • return remaining seconds or nil
WaitTimer.SetTime(id, delay)
  • reset the wait time
  • if <delay> is ommited the function will be triggert on next update

v1.5
- improved error checking
- "Wait" will reset fct,data when id is in use

Comments

Login to Curse

Don't have an account? Create One.

Get an epic experience with Curse Premium
  • Faster addon downloads
  • Premium-Only Beta Giveaways
  • Ad-Free Curse experience
  • Premium Curse Client
  • and many More Features
  • Learn More »

Infinite Crisis NA

Get Your Preferred Access Code!