Create a timer

timer [instructions] dt
(timer [instructions] dt delay)
(timer [instructions] dt delay n)

timer function dt
(timer function dt delay)
(timer function dt delay n)

timer signal dt
(timer signal dt delay)
(timer signal dt delay n)

Creates a timer which triggers the list of instructions, the function or sends the signal in the regular dt time intervals (specified in milliseconds). Initial delay and the number of iterations to do, n, can be provided optionally.

Example 1:

"t := (timer [(print :iter :dt :time)] 300 50 3)

Output:
Each line in the text output corresponds to the turtle name and an array {iteration no, time from the last trigger, total time from start}.

1 51.0078125 51.0078125
2 300.015625 351.0234375
3 300.0234375 651.046875

Example 2:
Programmatical termination of the timer (stoptimer instruction) is possible inside the triggered function code since the timer is available as the first argument of this function.

to fn :tx :iter :dt :time
  (print :iter :dt :time)
end

"t := (timer $fn 300 50 3)

Output:
Each line in the text output corresponds to the turtle name and an array {iteration no, time from the last trigger, total time from start}.

1 57.0078125 57.0078125
2 300.015625 357.0234375
3 300.0234375 657.046875

Example 3:

to onsignaltick :turtle :data
  (print :turtle :data)
end

"t := (timer "tick 300 50 3)

Output:
Each line in the text output corresponds to the turtle name and an array {iteration no, time from the last trigger, total time from start}.

first {1 49.9921875 49.9921875}
first {2 300.0234375 350.015625}
first {3 302.015625 652.03125}

See also:

Timer
Function as a value
Signal and event handling

Table of Content