Download
(3 Kb)
Download
Updated: 06-11-11 10:33 AM
Updated:06-11-11 10:33 AM
Created:06-11-11 10:33 AM
Downloads:127
Favorites:0
MD5:
libTimer
Version: 0.1
by: Terrasque [More]
This is a simple timer implentation for Rift addons to use.

As jnwhiteh have pointed out, this is technically not the most optimum way of doing it,but it is simple, and it is also pretty fast. Fast enough for the majority of practical uses.

The main problems will be with extremely many and/or very small repeating timers, as it has to update the timers index every time a timer is added or removed.

In those cases you'd probably be better of writing your own custom timer, anyway.

Commands
(params marked with * are optional)

timer_reference = StartTimer(seconds, callback, data*, repeating*)
Creates a timer, which will run when "seconds" value of time has passed.

seconds -- Seconds until the timer is run. Can be fractional numbers.
callback -- The callback function to run when the timer is up
data -- (Optional) Data to send to the callback
repeating -- (Optional) If the timer shall be repeating

Function returns a reference to the timer created
StopTimer(timer_reference)
Will stop an existing timer.

timer_reference -- The reference of the timer you want to stop
libTimer_SetDebug(int)
Will set the level of debug messages that will be shown.

int -- Value from 0 to 10. 0 means no messages (default), 10 means a lot of messages.

Examples

Very basic example

Code:
	function myFunc()
		print("This is a delayed function")
	end

	StartTimer(10, myFunc)


Sending data to callback

Code:
	function myFunc(v)
		print("This function was called with "..v)
	end

	StartTimer(10, myFunc, "The Power of Time!")

Repeating timer

Code:
	function myFunc()
		print("I rise! ..again")
	end

	wicked = StartTimer(10, myFunc, nil, 1)
Stop that repeating timer

Code:
	StopTimer(wicked)
Optional Files (0)


Post A Reply Comment Options
Unread 06-13-11, 06:04 PM  
Myrroddin
Endless Captain
AddOn Author - Click to view AddOns

Forum posts: 50
File comments: 8
Uploads: 4
Just curious...

I was wondering if I could get your support for LibStub to load LibTimer? You would gain the ability to version LibTimer, so if multiple copies are loaded by various addons, only the newest would stay in memory.

If you like the idea, here are the minor edits required. In RiftAddon.toc,
Code:
Name = "Lib: Timer"
RunOnStartup = {
    "LibStub.lua", -- if you put LS in its own subfolder, then "LibStub\LibStub.lua",
    "main.lua",
}
Then in main.lua
Code:
-- replace line 1 with
local MAJOR, MINOR = "LibTimer", 1
local libtimer = LibStub:NewLibrary(MAJOR, MINOR)
Myrroddin is offline Report comment to moderator  
Reply With Quote
Post A Reply



Category Jump: