2
2
mirror of https://github.com/Hilbis/Hilbish synced 2025-07-02 01:02:03 +00:00
Hilbish/docs/timers.md
sammyette e5eefb1d2d
refactor!: rework docs and doc command (#218)
changes the actual file format of docs to markup since that's basically what we have been
using in the first place.

the docgen command has been modified to write markdown headings with the function name and
yaml metadata for easy consumption by hugo for the website.

all other docs have been moved to markdown as well this is the main reason this is a "breaking" change
users will have to reinstall hilbish (task uninstall and task install) to remove the old plaintext docs
2022-12-15 00:00:54 -04:00

1.4 KiB

If you ever want to run a piece of code on a timed interval, or want to wait a few seconds, you don't have to rely on timing tricks, as Hilbish has a timer API to set intervals and timeouts.

These are the simple functions hilbish.interval and hilbish.timeout (doc accessible with doc hilbish). But if you want slightly more control over them, there is the hilbish.timers interface. It allows you to get a timer via ID.

Timer Interface

Functions

  • get(id) -> timer: get a timer via its id
  • create(type, ms, callback) -> timer: creates a timer, adding it to the timer pool. type is the type of timer it will be. 0 is an interval, 1 is a timeout. ms is the time it will run for in seconds. callback is the function called when the timer is triggered.

Timer Object

All those previously mentioned functions return a timer object, to which you can stop and start a timer again.

An example of usage: local t = hilbish.timers.create(1, 5000, function() print 'hello!' end)

t:stop() print(t.running, t.duration, t.type) t:start()

Properties

  • duration: amount of time the timer runs for in milliseconds
  • running: whether the timer is running or not
  • type: the type of timer (0 is interval, 1 is timeout)

Functions

  • stop(): stops the timer. returns an error if it's already stopped
  • start(): starts the timer. returns an error if it's already started