installTimer
Create a timer with the given ID and register it in the ContextTimerManager. Start the timer after the specified delay. If requested, repeat the timer at the specified frequency. When the timer fires, run the specified ogScript function.
Syntax
ogscript.installTimer (Timer ID, Repeat, Delay, Repeat Delay, Task);
Parameters
Parameter |
Type |
Required |
Description |
Timer ID |
String |
Yes |
ID of the timer to create and register in the ContextTimerManager. |
Repeat |
Boolean |
Yes |
true — repeat the timer using the specified Delay and Repeat Delay. false — only run the timer once, do not repeat the timer. |
Delay |
Long |
Yes |
Number of milliseconds to wait before starting the timer. |
Repeat Delay |
Long |
Yes |
How frequently the associated function runs, in milliseconds. |
Task |
Function |
Yes |
ogScript function to run when the timer fires. |
Returns
N/A
Example
This example creates a label named "Time" and a button named "Install Timer". When a user clicks the "Install Timer" button, an associated task runs a function named myFunction (), which creates a timer.
It also retrieves the time value every 30 seconds, and loads it into a variable named str which is displayed on the "Time" label. The myFunction () function uses the installTimer function to create the timer and set the rate at which the time data is updated.
<labelheight="80" id="timeLabel" left="43" name="Time" style="txt-align:west" top="26" width="275"/>
<buttonbuttontype="push" height="57" left="48" name="Install Timer" top="133" width="184">
<task tasktype="ogscript">function myFunction()
{
var date = new Date();
var str = date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();
ogscript.rename('timeLabel', 'Time:' + str);
}
//create a timer that starts immediately and runs myFunction every 30 seconds(30000 milliseconds)
ogscript.installTimer('myTimer', true, 0, 30000,myFunction);
</task>
</button>