WhiteSnoop How do I cheat?
Reputation: 1
Joined: 15 May 2009 Posts: 7 Location: http://alino.ucoz.com
|
Posted: Sat Jan 29, 2022 1:01 pm Post subject: Lua timer helper - uTimer |
|
|
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.
I wrote this little library for myself, but figured it might be of some use for others. Feel free to suggest or update the lib to your liking
Code: | uTimer
methods
update(1:string name, 2:table table) ---- can also call uTimer() instead, figured I'd be using this the most
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:
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 |
Description: |
|
 Download |
Filename: |
uTimer.lua |
Filesize: |
3.69 KB |
Downloaded: |
1105 Time(s) |
|
|