Timer
Timer allow to send a signal or trigger code execution in a regular time intervals. It is possible to configure
the interval length, a start delay and a number of triggers. Code triggered by the timer (list of instructions or
function specified when the timer is created) has access to variables with the timer iteration number, precise
time from the last trigger and from the timer startup.
Timer is working in the background. If a function or instruction list is associated with the timer, a task is
created and inserted in the turtle's task queue on each timer iteration. The next timer iteration cannot start
before the code triggered in the previous iteration is finished. It timer is configured to send signals
then the signal is sent to all turtles.
All time values are expressed in milliseconds.
Example 1:
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}
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:
"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
See also:
timer - create a timer
Table of Content