Module timer

Time related functions.

No dependency.

Module

new () Creates and return a new timer registry.
run ([func]) Create a new timer that will run a function.
tween (duration, tbl, to[, method="linear"]) Create a timer that will tween some numeric values.

Timer objects

Timer:after (time) Wait time milliseconds before running the function.
Timer:every (time) Run the function every time millisecond.
Timer:times (count) The function will not execute more than count times.
Timer:during (time) The timer will be active for a time duration.

Function conditions

Timer:initWhen (func) Starts the function execution when func() returns true.
Timer:startWhen (func) Starts the function execution when func() returns true.
Timer:repeatWhile (func) When the functions ends, the execution won’t stop and will repeat as long as func() returns true.
Timer:stopWhen (func) Stops the function execution when func() returns true.

Conditions override

Timer:start () Force the function to start its execution.
Timer:stop () Force the function to stop its execution.
Timer:abort () Force the function to stop immediately.
Timer:skip (time) Skip some amount of time.

Callbacks functions

Timer:onStart (func) Add a function to the start callback: will execute func(self, lag) when the function execution start.
Timer:onUpdate (func) Add a function to the update callback: will execute func(self, lag) each frame the main function is run.
Timer:onEnd (func) Add a function to the end callback: will execute func(self, lag) when the function execution end.

Chaining

Timer:chain (func) Creates another timer which will be replace the current one when it ends.

Management

Timer:update (dt) Update the timer.
Timer:dead () Check if the timer is dead.

TimerRegistry objects

TimerRegistry:update (dt) Update all the timers in the registry.
TimerRegistry:run (func) Create a new timer and add it to the registry.
TimerRegistry:tween (duration, tbl, to, method) Create a new tween timer and add it to the registry.
TimerRegistry:clear () Cancels all the running timers in this registry.

TweenTimer objects

r.chain (_, duration_, tbl_, to_, method_) Creates another tween which will be initialized when the current one ends.


Module

new ()
Creates and return a new timer registry. A timer registry provides an easy way to handle your timers; it will keep track of them, updating and removing them as needed. If you use the scene system, a scene-specific timer registry is available at ubiquitousse.scene.current.timer.

Returns:

    TimerRegistry
run ([func])
Create a new timer that will run a function. The function will receive as first parameter the timer object. As a second parameter, the function will receive the delta time (dt). As a third parameter, the function will receive the lag time (difference between the time when the function was run and when it should have been run). As a fourth parameter, the function will receive as first parameter the wait(time) function, which will pause the function execution for time miliseconds. You will need to call the :update(dt) method on the timer object every frame to make it do something, or create the timer from a timer registry if you don’t want to handle your timers manually.

Parameters:

  • func function the function to schedule (optional)

Returns:

    Timer the object
tween (duration, tbl, to[, method="linear"])
Create a timer that will tween some numeric values. You will need to call the :update(dt) method on the timer object every frame to make it do something, or create the timer from a timer registry if you don’t want to handle your timers manually.

Parameters:

  • duration number tween duration (miliseconds)
  • tbl table the table containing the values to tween
  • to table the new values
  • method string/function tweening method (string name or the actual function(time, start, change, duration)) (default "linear")

Returns:

    TweenTimer the object. A duration is already defined, and the :chain methods takes the same arguments as tween (and creates a tween).

Timer objects

Timer methods.
Timer:after (time)
Wait time milliseconds before running the function. Specify no time to remove condition.

Parameters:

  • time
Timer:every (time)
Run the function every time millisecond. Specify no time to remove condition.

Parameters:

  • time
Timer:times (count)
The function will not execute more than count times. Specify no time to remove condition.

Parameters:

  • count
Timer:during (time)
The timer will be active for a time duration. Specify no time to remove condition.

Parameters:

  • time

Function conditions

Timer:initWhen (func)
Starts the function execution when func() returns true. Checked before the “after” condition, meaning the “after” countdown starts when func() returns true. If multiple init functions are added, init will trigger only when all of them returns true.

Parameters:

  • func
Timer:startWhen (func)
Starts the function execution when func() returns true. Checked after the “after” condition. If multiple start functions are added, start will trigger only when all of them returns true.

Parameters:

  • func
Timer:repeatWhile (func)
When the functions ends, the execution won’t stop and will repeat as long as func() returns true. Will cancel timed repeat conditions if false but needs other timed repeat conditions to be true to create a new repeat. If multiple repeat functions are added, a repeat will trigger only when all of them returns true.

Parameters:

  • func
Timer:stopWhen (func)
Stops the function execution when func() returns true. Checked before all timed conditions. If multiple stop functions are added, stop will trigger only when all of them returns true.

Parameters:

  • func

Conditions override

Timer:start ()
Force the function to start its execution.
Timer:stop ()
Force the function to stop its execution.
Timer:abort ()
Force the function to stop immediately. Won’t trigger onEnd or other callbacks.
Timer:skip (time)
Skip some amount of time.

Parameters:

  • time

Callbacks functions

Timer:onStart (func)
Add a function to the start callback: will execute func(self, lag) when the function execution start.

Parameters:

  • func
Timer:onUpdate (func)
Add a function to the update callback: will execute func(self, lag) each frame the main function is run.

Parameters:

  • func
Timer:onEnd (func)
Add a function to the end callback: will execute func(self, lag) when the function execution end.

Parameters:

  • func

Chaining

Timer:chain (func)
Creates another timer which will be replace the current one when it ends. Returns the new timer (and not the original one!).

Parameters:

  • func

Returns:

    Timer

Management

Timer:update (dt)
Update the timer. Should be called at every game update.

Parameters:

  • dt number the delta-time (time spent since last time the function was called) (miliseconds)
Timer:dead ()
Check if the timer is dead. You shouldn’t need to worry about this if your timer belongs to a registry. If you don’t use registries, you probably should purge dead timers to free up some memory (dead timers don’t do anything otherwise).

Returns:

    bool true if the timer can be discarded, false if it’s still active.

TimerRegistry objects

Registry methods.
TimerRegistry:update (dt)
Update all the timers in the registry. Should be called at every game update; called by ubiquitousse.update.

Parameters:

  • dt number the delta-time (time spent since last time the function was called) (miliseconds)
TimerRegistry:run (func)
Create a new timer and add it to the registry. Same as timer_module.run, but add it to the registry.

Parameters:

  • func
TimerRegistry:tween (duration, tbl, to, method)
Create a new tween timer and add it to the registry. Same as timer_module.tween, but add it to the registry.

Parameters:

  • duration
  • tbl
  • to
  • method
TimerRegistry:clear ()
Cancels all the running timers in this registry.

TweenTimer objects

Tween timer: inherit all fields and methods from Timer and change a few to make them easier to use in a tweening context.
r.chain (_, duration_, tbl_, to_, method_)
Creates another tween which will be initialized when the current one ends. If tbl and/or method are not specified, the values from the current tween will be used. Returns the new tween.

Parameters:

  • _
  • duration_
  • tbl_
  • to_
  • method_

Returns:

    TweenTimer
generated by LDoc 1.4.6 Last updated 2021-12-25 20:46:24