CAPL Script

SetTimer

This reference collection includes Vector documentation reproduced with permission. Snippets may require configuration-specific symbols and are not all standalone programs. Sources and validation limits.

Syntax

void setTimer(msTimer t, long duration); // form 1

void setTimer(timer t, long duration); // form 2

void setTimer(timer t, long durationSec, long durationNanoSec); // form 3

Method(Dynamic)

void msTimer::set(long);

Function

Sets a timer.

Parameters

Timer or msTimer variable and an expression which specifies the duration of the timer.

Return Values

—

Example: compare timer units

The first argument's type matters: the two-argument msTimer overload uses milliseconds, while the two-argument timer overload uses seconds. In the three-argument timer overload, the extra part is expressed in nanoseconds. Check that overload's availability in your installed version.

These key handlers illustrate separate scheduling choices. They are not measured timing results, and the snippet has not been compiled in your configuration.

variables
{
  msTimer t1;
  timer t23;
}

on key F1
{
  setTimer(t1, 200); // 200 milliseconds
}

on key F2
{
  setTimer(t23, 2); // 2 seconds
}

on key F3
{
  setTimer(t23, 0, 1250 * 1000); // 1.25 milliseconds in nanoseconds
}

on timer t1
{
  write("The t1 timer event occurred");
}

on timer t23
{
  write("The t23 timer event occurred");
}

To check the units, run one trigger at a time and compare the scheduling point with the resulting timer event in your test setup. Do not confuse the requested duration with a recorded latency measurement.

For periodic behavior, inspect whether the example reschedules the timer from its handler. A single setTimer call alone does not express a repeating interval. See cancelTimer when the pending work needs to be cancelled.