Skip to content

Timer

Deprecated

Use Wait.frames(...) instead.

Timer is a static global class which provides methods for executing other functions after a delay and/or repeatedly. Each Timer is tracked by a unique "identifier" string.

Warning

The "identifiers" are shared between Global and all Object scripts, so each Timer must have a unique name.

Function Summary

Function Name Description Return  
create( parameters) Creates a Timer. It will auto-delete once its repetitions have been completed.
destroy( identifier) Destroys a Timer.

Function Details

create(...)

Creates a Timer. It will auto-delete once its repetitions have been completed.

create(parameters)

  • parameters: A Table containing the information used to start the Timer.
    • identifier: Timer's name, used to destroy it. Must be unique within all other scripts.
    • function_name: Name of function to trigger when time is reached.
    • function_owner: Where the function from function_name exists.
      • Optional, defaults to the calling Object.
    • parameters: Table containing any data that will be passed to the function.
      • Optional, will not be used by default.
    • delay: Length of time in seconds before the function is triggered.
      • Optional, defaults to 0.
      • 0 results in a delay of 1 frame before the triggered function activates.
    • repetitions: Number of times the countdown repeats.
      • Optional, defaults to 1.
      • Use 0 for infinite repetitions.
function onLoad()
    dataTable = {welcome="Hello World!"}
    Timer.create({
        identifier     = "A Unique Name",
        function_name  = "fiveAfterOne",
        parameters     = dataTable,
        delay          = 1,
        repetitions    = 5,
    })
end

function fiveAfterOne(params)
    print(params.welcome)
end

Tip

If your timer is on an Object, a good way to establish a unique identifier for it is to use the item's GUID!


destroy(...)

Destroys a Timer. A timer, if it completes its number of repetitions, will automatically destroy itself.

destroy(identifier)

  • identifier: The unique identifier for the timer you want to destroy.