Lua utility module Timer

Basic timer - after a specified number of seconds, the specified thing happens.

Usage:

local Timer = require("Timer")

LevelFuncs.FinishTimer = function(healthWhenStarted, victoryMessage)
    DoSomething(healthWhenStarted, victoryMessage)
end

LevelFuncs.TriggerTimer = function(obj)
    local myTimer = Timer.Create("my_timer", 5.0, false, true, "FinishTimer", Lara:GetHP(), "Well done!")
    myTimer:Start()
end

LevelFuncs.OnControlPhase = function(dt)
    Timer.UpdateAll(dt)
end

Functions

Create(name, totalTime, loop, showString, func, funcArgs) Create (but do not start) a new timer.
Get(name) Get a timer by its name.
SetFunction(t, func, funcArgs) Give the timer a new function and args
Start(t) Begin or unpause a timer.
Pause(t) Pause the timer.
Stop(t) Stop the timer.
GetRemainingTime(t) Get the remaining time for a timer.
SetRemainingTime(t, remainingTime) Set the remaining time for a timer
GetTotalTime(t) Get the total time for a timer.
SetTotalTime(t, totalTime) Set the total time for a timer
SetLooping(t, looping) Set whether or not the timer loops
UpdateAll(dt) Update all active timers.


Functions

Create(name, totalTime, loop, showString, func, funcArgs)
Create (but do not start) a new timer.

Parameters:

  • name string A label to give this timer; used to retrieve the timer later
  • totalTime number The duration of the timer, in seconds
  • loop bool if true, the timer will start again immediately after the time has elapsed
  • showString bool if true, the remaining time, rounded up, will show at the bottom of the screen. At any given time, only one timer can show its remaining time.
  • func string The name of the LevelFunc member to call when the time is up
  • funcArgs the arguments with which the above function will be called

Returns:

    The timer in its paused state
Get(name)
Get a timer by its name.

Parameters:

  • name string The label that was given to the timer when it was created

Returns:

    The timer
SetFunction(t, func, funcArgs)
Give the timer a new function and args

Parameters:

  • t the timer in question
  • func string The name of the LevelFunc member to call when the time is up
  • funcArgs the arguments with which the above function will be called
Start(t)
Begin or unpause a timer. If showing the remaining time on-screen, its color will be set to white.

Parameters:

  • t the timer in question
Pause(t)
Pause the timer. If showing the remaining time on-screen, its color will be set to yellow.

Parameters:

  • t the timer in question
Stop(t)
Stop the timer.

Parameters:

  • t the timer in question
GetRemainingTime(t)
Get the remaining time for a timer.

Parameters:

  • t the timer in question

Returns:

    the time in seconds remaining on the clock
SetRemainingTime(t, remainingTime)
Set the remaining time for a timer

Parameters:

  • t the timer in question
  • remainingTime number the new time remaining for the timer
GetTotalTime(t)
Get the total time for a timer. This is the amount of time the timer will start with, as well as when starting a new loop

Parameters:

  • t the timer in question

Returns:

    the timer's total time
SetTotalTime(t, totalTime)
Set the total time for a timer

Parameters:

  • t the timer in question
  • totalTime number timer's new total time
SetLooping(t, looping)
Set whether or not the timer loops

Parameters:

  • t the timer in question
  • looping bool whether or not the timer loops
UpdateAll(dt)
Update all active timers. Should be called in LevelFuncs.OnControlPhase

Parameters:

  • dt number The time in seconds since the last frame
generated by LDoc 1.4.6 Last updated 2022-08-01 20:38:26