A library which provides easy and advanced timers for module developers
:warning: This library is still in beta phase. Use at your own risk! Contributions are always welcome
A library which provides easy and advanced timers for module developers.
This project is inspired by mk’s timer library, make sure to support that project too :heart:
Background
As normal players - who aren’t in module team - aren’t allowed to use the Module
API’s timers (system.newTimer
and system.removeTimer
), I decided to create a
brand new, advanced timer system for the benefit of all!
There are many capabilities for these timers
To use this library you need to insert this libraries code in top of your code.
Use the full code (Recommended for studying) | Use the minified version (Recommended for production use)
--insert the library code here
local timer1 = Timer("timer1", function() end, 5000, false) -- Creating a very basic timer with a timeout value of 5000
function eventLoop()
Timer.process() -- You need to call this method inside eventLoop to start and process timers
end
--a function to greet a user
function greet(name, nice)
print("Hello" .. name .. "It seems you are " .. (nice and "nice" or "not nice"))
end
-- storing the timer in a variable is optional. Storing will be useful if you need to access information about the timer
Timer("callback", greet, 2000, false, "Seniru", true) --setting the callback to our greet function and pass "Seniru" and true as arguments
function eventLoop()
Timer.process()
end
--Run this code to see the results!
Timer("looping", function() print("prints") end, 3000, true)
-- This would print `prints` every 3 seconds. Note that you need to specify the time in milliseconds
Do you want to contribute this project? Great! There are many way that you can involve!
Please, make sure that you have searched well before creating a new issue or a pull request. I’m actively responding to all kind of contributions :smile:
Thanks goes to these wonderful people (emoji key):
Seniru Pasan Indira 💻 |
All Contributors 🚇 |
Lautenschlager 💻 🐛 |
Iván 🐛 |
This project follows the all-contributors specification. Contributions of any kind welcome!