⏱️ Timer
Execute code at specified time intervals

The shortest interval possible is equal to the local Tick Rate - usually at 33ms. On the Server this can vary depending on the Config.toml setting.
🎒 Examples
-- 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)
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)
🗿 Static Functions
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() | |
GetElapsedTime: integer | Returns the time elapsed since the last tick | |
GetRemainingTime: integer | Returns the time remaining to the next tick | |
IsValid: boolean | 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 | |
SetInterval: integer | Same as SetTimeout(), but repeats the execution of the function continuously | |
SetRemainingTime | Sets the time remaining to the next tick | |
SetTimeout: integer | Executes a function, after waiting a specified number of milliseconds | |
Unbind: boolean | Unbinds a Timer from an Actor it was bound to with Timer.Bind, without clearing or resetting the Timer |

BindOptimal
Binds a Timer to any Actor. The timer will be automatically cleared when the Actor is destroyed
Timer.Bind(timer_id, actor)
Parameters
| Name | Type | Beschreibung |
|---|---|---|
timer_id | integer | The Timer ID |
actor | Base Actor | Actor to be bound |
Examples (1)
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)

ClearIntervalOptimal
Stops the execution of the function specified in SetInterval()
Timer.ClearInterval(interval_id)
Parameters
| Name | Type | Beschreibung |
|---|---|---|
interval_id | integer | The ID value returned by SetInterval() is used as the parameter for this method |

ClearTimeoutOptimal
Stops the execution of the function specified in SetTimeout()
Timer.ClearTimeout(timeout_id)
Parameters
| Name | Type | Beschreibung |
|---|---|---|
timeout_id | integer | The ID value returned by SetTimeout() is used as the parameter for this method |

GetElapsedTimeOptimal
Returns the time elapsed since the last tick
local elapsed_time = Timer.GetElapsedTime(timer_id)
Parameters
| Name | Type | Beschreibung |
|---|---|---|
timer_id | integer | The Timer ID |
Returns
| Type | Beschreibung |
|---|---|
| integer | Time elapsed since the last tick |

GetRemainingTimeOptimal
Returns the time remaining to the next tick
local remaining_time = Timer.GetRemainingTime(timer_id)
Parameters
| Name | Type | Beschreibung |
|---|---|---|
timer_id | integer | The Timer ID |
Returns
| Type | Beschreibung |
|---|---|
| integer | Time remaining to the next tick |
See also SetRemainingTime.

IsValidOptimal
Checks if a Timer is currently active or waiting to be triggered
local is_valid = Timer.IsValid(timer_id)
Parameters
| Name | Type | Beschreibung |
|---|---|---|
timer_id | integer | The Timer ID |
Returns
| Type | Beschreibung |
|---|---|
| boolean | Whether a Timer is currently active or waiting to be triggered |

PauseOptimal
Pauses the Timer
Timer.Pause(timer_id)
Parameters
| Name | Type | Beschreibung |
|---|---|---|
timer_id | integer | The Timer ID |

ResetElapsedTimeOptimal
Resets a Timer to restart from beginning
Timer.ResetElapsedTime(timer_id)
Parameters
| Name | Type | Beschreibung |
|---|---|---|
timer_id | integer | The Timer ID |

ResumeOptimal
Resumes the Timer
Timer.Resume(timer_id)
Parameters
| Name | Type | Beschreibung |
|---|---|---|
timer_id | integer | The Timer ID |

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

SetRemainingTimeModerate
Sets the time remaining to the next tick
Timer.SetRemainingTime(timer_id, time)
Parameters
| Name | Type | Beschreibung |
|---|---|---|
timer_id | integer | The Timer ID |
time | integer | Die verbleibende Zeit in Millisekunden |
See also GetRemainingTime.

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

UnbindOptimal
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
| Name | Type | Beschreibung |
|---|---|---|
timer_id | integer | The Timer ID |
actor | Base Actor | Actor to be unbound |
Returns
| Type | Beschreibung |
|---|---|
| boolean | true if the Timer was bound to this Actor and got unbound |
🚀 Events
This class doesn't have own events.

