2022-12-15 04:00:54 +00:00
|
|
|
---
|
2023-08-26 15:30:51 +00:00
|
|
|
title: Module hilbish.timers
|
2022-12-15 04:00:54 +00:00
|
|
|
description: timeout and interval API
|
|
|
|
layout: doc
|
|
|
|
menu:
|
|
|
|
docs:
|
|
|
|
parent: "API"
|
|
|
|
---
|
|
|
|
|
|
|
|
## Introduction
|
2022-12-28 23:33:44 +00:00
|
|
|
|
|
|
|
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
|
2023-12-04 00:54:00 +00:00
|
|
|
accessible with `doc hilbish`, or `Module hilbish` on the Website).
|
2022-12-28 23:33:44 +00:00
|
|
|
|
|
|
|
An example of usage:
|
2023-12-04 00:54:00 +00:00
|
|
|
```lua
|
2023-01-18 10:39:26 +00:00
|
|
|
local t = hilbish.timers.create(hilbish.timers.TIMEOUT, 5000, function()
|
2022-12-28 23:33:44 +00:00
|
|
|
print 'hello!'
|
|
|
|
end)
|
|
|
|
|
|
|
|
t:start()
|
2023-01-18 10:39:26 +00:00
|
|
|
print(t.running) // true
|
2022-12-28 23:33:44 +00:00
|
|
|
```
|
2022-12-15 04:00:54 +00:00
|
|
|
|
2023-09-02 18:18:40 +00:00
|
|
|
## Functions
|
|
|
|
|||
|
|
|
|
|----|----|
|
2023-12-04 00:54:00 +00:00
|
|
|
|<a href="#timers.create">create(type, time, callback) -> @Timer</a>|Creates a timer that runs based on the specified `time`.|
|
2023-09-02 18:18:40 +00:00
|
|
|
|<a href="#timers.get">get(id) -> @Timer</a>|Retrieves a timer via its ID.|
|
|
|
|
|
2023-09-02 20:11:57 +00:00
|
|
|
## Static module fields
|
2023-09-02 20:01:57 +00:00
|
|
|
|||
|
|
|
|
|----|----|
|
|
|
|
|INTERVAL|Constant for an interval timer type|
|
|
|
|
|TIMEOUT|Constant for a timeout timer type|
|
2022-12-21 01:00:31 +00:00
|
|
|
|
2023-09-02 20:11:57 +00:00
|
|
|
<hr><div id='timers.create'>
|
2023-09-02 18:18:40 +00:00
|
|
|
<h4 class='heading'>
|
|
|
|
hilbish.timers.create(type, time, callback) -> <a href="/Hilbish/docs/api/hilbish/hilbish.timers/#timer" style="text-decoration: none;" id="lol">Timer</a>
|
|
|
|
<a href="#timers.create" class='heading-link'>
|
|
|
|
<i class="fas fa-paperclip"></i>
|
|
|
|
</a>
|
|
|
|
</h4>
|
|
|
|
|
2023-12-04 00:54:00 +00:00
|
|
|
Creates a timer that runs based on the specified `time`.
|
2023-08-26 15:30:51 +00:00
|
|
|
#### Parameters
|
2023-12-04 00:54:00 +00:00
|
|
|
`number` **`type`**
|
|
|
|
What kind of timer to create, can either be `hilbish.timers.INTERVAL` or `hilbish.timers.TIMEOUT`
|
|
|
|
|
|
|
|
`number` **`time`**
|
|
|
|
The amount of time the function should run in milliseconds.
|
|
|
|
|
|
|
|
`function` **`callback`**
|
|
|
|
The function to run for the timer.
|
|
|
|
|
2023-09-02 20:01:57 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<hr><div id='timers.get'>
|
2023-09-02 18:18:40 +00:00
|
|
|
<h4 class='heading'>
|
|
|
|
hilbish.timers.get(id) -> <a href="/Hilbish/docs/api/hilbish/hilbish.timers/#timer" style="text-decoration: none;" id="lol">Timer</a>
|
|
|
|
<a href="#timers.get" class='heading-link'>
|
|
|
|
<i class="fas fa-paperclip"></i>
|
|
|
|
</a>
|
|
|
|
</h4>
|
2023-01-18 10:39:26 +00:00
|
|
|
|
2023-12-02 12:23:49 +00:00
|
|
|
Retrieves a timer via its ID.
|
2023-08-26 15:30:51 +00:00
|
|
|
#### Parameters
|
2023-12-04 00:54:00 +00:00
|
|
|
`number` **`id`**
|
|
|
|
|
|
|
|
|
2023-09-02 20:01:57 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
## Types
|
2023-09-02 20:11:57 +00:00
|
|
|
<hr>
|
|
|
|
|
2023-01-18 10:39:26 +00:00
|
|
|
## Timer
|
|
|
|
The Job type describes a Hilbish timer.
|
2023-09-02 20:11:57 +00:00
|
|
|
## Object properties
|
|
|
|
|||
|
|
|
|
|----|----|
|
|
|
|
|type|What type of timer it is|
|
|
|
|
|running|If the timer is running|
|
|
|
|
|duration|The duration in milliseconds that the timer will run|
|
|
|
|
|
2022-12-15 04:00:54 +00:00
|
|
|
|
2023-01-18 10:39:26 +00:00
|
|
|
### Methods
|
|
|
|
#### start()
|
2022-12-15 04:00:54 +00:00
|
|
|
Starts a timer.
|
|
|
|
|
2023-01-18 10:39:26 +00:00
|
|
|
#### stop()
|
2022-12-15 04:00:54 +00:00
|
|
|
Stops a timer.
|
|
|
|
|