⏱️ Timer
Execute code at specified time intervals.

info
L'intervalle le plus court possible est égal au tick rate local, généralement 33 ms. Sur le serveur, il peut varier selon le réglage du Config.toml.
🎒 Exemples
-- creates a Interval to call a function at every 2 seconds
local param1, param2 = "awesome param 1", 456
local my_interval = Timer.SetInterval(function()
-- param1 and param2 are captured by the function itself
Console.Log("Triggered each 2 seconds! Param1: " .. param1 .. ". Param2: " .. param2)
end, 2000)
-- cancels the Interval
Timer.ClearInterval(my_interval)
-- creates a Timeout to call a function in 5 seconds, once
local my_param = "world"
Timer.SetTimeout(function()
Console.Log("nanos " .. my_param)
end, 5000)
(Timer.Bind) Binding a Timer to an Entity
local character = Character(Vector(), Rotator(), "nanos-world::SK_Male")
local my_timer = Timer.SetTimeout(function(_character)
-- Do something with _character
-- Ex: Destroy the character after 10 seconds
_character:Destroy()
end, 10000, character)
-- Binds the Timer to the Character
-- This will ensure it will never trigger if the character is destroyed before it
-- With this you don't need to validate if the '_character' parameter is valid
Timer.Bind(my_timer, character)
🗿 Fonctions statiques
| Returns | Name | Description | |
|---|---|---|---|
Bind | Binds a Timer to any Actor. The timer will be automatically cleared when the Actor is destroyed | ||
ClearInterval | Stops the execution of the function specified in SetInterval() | ||
ClearTimeout | Stops the execution of the function specified in SetTimeout() | ||
| integer | GetElapsedTime | Returns the time elapsed since the last tick | |
| integer | GetRemainingTime | Returns the time remaining to the next tick | |
| boolean | IsValid | Checks if a Timer is currently active or waiting to be triggered | |
Pause | Pauses the Timer | ||
ResetElapsedTime | Resets a Timer to restart from beginning | ||
Resume | Resumes the Timer | ||
| integer | SetInterval | Same as SetTimeout(), but repeats the execution of the function continuously | |
SetRemainingTime | Sets the time remaining to the next tick | ||
| integer | SetTimeout | Executes a function, after waiting a specified number of milliseconds | |
| boolean | Unbind | Unbinds a Timer from an Actor it was bound to with Timer.Bind, without clearing or resetting the Timer |
Optimal

Bind
Binds a Timer to any Actor. The timer will be automatically cleared when the Actor is destroyed
Timer.Bind(timer_id, actor)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| integer | timer_id | Required parameter | The Timer ID |
| Base Actor | actor | Required parameter | Actor to be bound |
Timer.Bind Examples
Binding a Timer to an Entity
local character = Character(Vector(), Rotator(), "nanos-world::SK_Male")
local my_timer = Timer.SetTimeout(function(_character)
-- Do something with _character
-- Ex: Destroy the character after 10 seconds
_character:Destroy()
end, 10000, character)
-- Binds the Timer to the Character
-- This will ensure it will never trigger if the character is destroyed before it
-- With this you don't need to validate if the '_character' parameter is valid
Timer.Bind(my_timer, character)
Optimal

ClearInterval
Stops the execution of the function specified in SetInterval()
Timer.ClearInterval(interval_id)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| integer | interval_id | Required parameter | The ID value returned by SetInterval() is used as the parameter for this method |
Optimal

ClearTimeout
Stops the execution of the function specified in SetTimeout()
Timer.ClearTimeout(timeout_id)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| integer | timeout_id | Required parameter | The ID value returned by SetTimeout() is used as the parameter for this method |
Optimal

GetElapsedTime
Returns the time elapsed since the last tick
local elapsed_time = Timer.GetElapsedTime(timer_id)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| integer | timer_id | Required parameter | The Timer ID |
Returns
| Type | Description |
|---|---|
| integer | Time elapsed since the last tick |
Optimal

GetRemainingTime
Returns the time remaining to the next tick
local remaining_time = Timer.GetRemainingTime(timer_id)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| integer | timer_id | Required parameter | The Timer ID |
Returns
| Type | Description |
|---|---|
| integer | Time remaining to the next tick |
See also SetRemainingTime.
Optimal

IsValid
Checks if a Timer is currently active or waiting to be triggered
local is_valid = Timer.IsValid(timer_id)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| integer | timer_id | Required parameter | The Timer ID |
Returns
| Type | Description |
|---|---|
| boolean | Whether a Timer is currently active or waiting to be triggered |
Optimal

Pause
Pauses the Timer
Timer.Pause(timer_id)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| integer | timer_id | Required parameter | The Timer ID |
Optimal

ResetElapsedTime
Resets a Timer to restart from beginning
Timer.ResetElapsedTime(timer_id)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| integer | timer_id | Required parameter | The Timer ID |
Optimal

Resume
Resumes the Timer
Timer.Resume(timer_id)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| integer | timer_id | Required parameter | The Timer ID |
Optimal

SetInterval
Same as SetTimeout(), but repeats the execution of the function continuously
local ret = Timer.SetInterval(callback, milliseconds?, parameters...?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| function | callback | Required parameter | The callback that will be executed. Return false to stop it from being called. |
| integer | milliseconds? | 0 | The time in milliseconds the timer should delay in between executions of the specified function |
| any | parameters...? | nil | Additional parameters to pass to the function |
Returns
| Type | Description |
|---|---|
| integer | the interval_id |
Moderate

SetRemainingTime
Sets the time remaining to the next tick
Timer.SetRemainingTime(timer_id, time)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| integer | timer_id | Required parameter | The Timer ID |
| integer | time | Required parameter | The time remaining in milliseconds |
See also GetRemainingTime.
Optimal

SetTimeout
Executes a function, after waiting a specified number of milliseconds
local ret = Timer.SetTimeout(callback, milliseconds?, parameters...?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| function | callback | Required parameter | The callback that will be executed |
| integer | milliseconds? | 0 | The time in milliseconds to wait before executing the function |
| any | parameters...? | nil | Additional parameters to pass to the function |
Returns
| Type | Description |
|---|---|
| integer | the timeout_id |
Optimal

Unbind
Unbinds a Timer from an Actor it was bound to with Timer.Bind, without clearing or resetting the Timer
local ret = Timer.Unbind(timer_id, actor)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| integer | timer_id | Required parameter | The Timer ID |
| Base Actor | actor | Required parameter | Actor to be unbound |
Returns
| Type | Description |
|---|---|
| boolean | true if the Timer was bound to this Actor and got unbound |
🚀 Événements
This class doesn't have own events.

