timeTable = timeTable or {} uTimer = uTimer or {} uTimer.Table = uTimer.Table or {} local e = uTimer local timeTable = e.Table function e.make(name, func, interval, disabled) -- check if already exists, destroy if so if timeTable[name] then print("Overwriting existing timer: {timeTable."..name.."}") timeTable[name].destroy() timeTable[name] = nil end -- create timer timeTable[name] = createTimer() local timer = timeTable[name] timer.Interval = interval or 1000 timer.Enabled = disabled or true timer.OnTimer = func or nil return timer end function e.listActive() local timers = "Active Timers: " local count = 0 for i, k in pairs(timeTable) do count = count + 1 if k.Enabled then timers = timers..i..", " end end if count > 0 then print(timers) end end function e.purgeAll() for name, timer in pairs(timeTable) do timer.destroy() timeTable[name] = nil end end function e.purge(name) if timeTable[name] then timeTable[name].destroy() timeTable[name] = nil end end function e.update(name, tbl) if not timeTable[name] then e.make(name) end if tbl and type(tbl) == "table" then local timer = timeTable[name] for param, value in pairs(tbl) do timeTable[name][param] = value end end end -- makes uTimer() work as uTimer.update(), gotta love them metatables :) setmetatable(uTimer, {__call = function(self, name, tabl) self.update(name, tabl) end}) ---- documentation? --[[ I am a strong ``local`` user. Whenever defining variables I don't want to keep around (or add to the global table, who knows what we're overwriting!) However, when you would do: local someVar = createTimer() Eventually the local "someVar" would not be available anymore (especially during testing in the Lua Engine window) So you would end up with creating another timer everytime you hit execute. I created this library to do that for us. The most important key for me was to keep all timers in a table so I was able to track them. Or to purge all timers Well without further ado, here is the somewhat documentation: uTimer methods update(1:string name, 2:table table) will make a new timer if it doesn't exist, kinda making ''make()'' useless the table requires parametersnames to be what the timer object expects Enabled, OnTimer, Interval etc... Create Example: --- can call it as uTimer("SomeTimer" ...) etc aswell uTimer.update("SomeTimer", { Enabled = true, -- don't need to supply on creation, but better safe than insanity right? OnTimer = function() print("Hello uTimer!") end, Interval = 1000 }) Update Function Example: uTimer.update("SomeTimer", {OnTimer = function() print("No more, mr Hello uTimer!") end}) Disable Example: uTimer.update("SomeTimer", {Enabled = false}) make(1:string name, 2:function func, 3:number interval, 4:boolean disabled) makes a new timer object and stores it in the uTimer.Table to be accessed. Allows to make a simple timer object returns timerObject purge(1:string name) purges (destroys) the given timer in the uTimer.Table purgeAll() purges (destroys) all the timers in the uTimer.Table listActive() primitively prints active timers to the Lua Engine window Table is used to store all timers that are created through this lib can read manually from like (uTimer.Table["SomeTimer"] or uTimer.Table.SomeTimer) will return the timer object --]] ----