timer
The timer
script command is used to start or stop a timer for an entity. Timers can optionally be given a name which can be used to stop that specific timer using timer off
. Using the same non-empty name again will replace the timer as if timer off
was called before the second invocation. Multiple anonymous timers with no name can be started at the same time.
To stop all timers set by the entity instance script for the calling entity use timer kill_local
. This will also prevent the completion command from an in-progress playanim -e
command called from the entity instance script from being run. Unnamed timers for entity class scripts cannot be stopped prematurely (short of destroying the entity).
ℹ️ Unlike all other commands and their parameters, the optional timer name parameter comes directly after the command name without any space and before any flags. All underscores in the timer name are ignored and you cannot use ~variable~
substitution or quoted strings.
If you don't want to run anything exactly when some time expires but only want to check if a certain amount of time has elapsed then see the starttimer
command.
Usage
timer [-mi] <count*> <interval*> <command...>
timer<name> [-mi] <count*> <interval*> <command...>
timer<name> off
timer kill_local
Context: Any Entity
Flags:
-m
: Duration is given in milliseconds instead of seconds
-i
: Only run the timer if the player is near the entity
Parameters:
Parameter | Type | Description |
---|---|---|
name |
string |
Timer name - must be directly after the command name and all underscores are ignored |
count |
int or variable |
Number of times that the timer should fire - 0 to repeat indefinitely |
interval |
number or variable |
Number of seconds (or milliseconds with -m ) until the timer fires |
command |
command |
A command to execute each time the timer fires |
The specified <command>
is run <count>
times, each time after the given <interval>
has elapsed since the last time (or since the timer
command was executed). If <count>
is 0
then the timer repeats forever until it is stopped manually. Timers with interval 0 fire once per frame.
Idle timers started with the -i
flag will only execute the given command if the timer fires while the player is "near" the entity. The times when the player is not near the entity do not count against the given <count>
- e.g. timer -i 1 1 herosay hello
will display hello
exactly once when the player gets near to the calling entity. Scripts should not rely on the exact definition of "near" except that all visible entities or those in the same room as the player are considered to be "near". Instead of idle timers you can listen for the heartbeat event set using setmainevent
(main
by default) if you do not require any precise timing guarantees.
ℹ️ In versions before Arx Libertatis 1.3, the interval must be an integer and must not be 0 for idle timers