timer, stoptimer - Create a timer that executes a function
timer(
ms, fun )
stoptimer( n )
timer() creates a timer that will fire ms milliseconds after it is created. When it fires, the function passed in as fun will execute. The function should not include parentheses or arguments. Only the name of the function should be passed in as a reference. timer() returns an integer identifier that can be used to cancel the timer.
stoptimer() cancels a previously created timer that has not yet fired. The argument n should be the value returned by a earlier call to timer().
timer() returns a unique identifier to the newly created timer.
stoptimer() has no return value.
Using parentheses for the fun argument when calling timer() produces a variety of unexpected behaviors.
The following
example from page 10 of the Tranquility Manual
https://www.cs.drexel.edu/~bls96/tranquility.pdf
implements a simple stopwatch.
var tim, lab, labstr, sec fun init() { labstr : alloc(10) secs : 0 html("<center0) lab : makelabel("0") html("<br>0) button("Start", swstart) button("Stop", swstop) button("Reset", swreset) } fun swstart() { tim : timer(1000, timestep) } fun swstop() { stoptimer(.tim) } fun swreset() { secs : 0 setlabel(.lab, "0") } fun timestep() { time : timer(1000, timestep) secs : .secs + 1 i2s(.labstr, .secs) setlabel(.lab, .labstr) }
Charlie Stuart cstuart11@protonmail.com
First, check
the Tranquility Programmer’s Manual
https://www.cs.drexel.edu/~bls96/tranquility.pdf
If the problem persists see Dr. Stuart or Charlie Stuart
Dr. Stuart:
brian.l.stuart@drexel.edu
Charlie Stuart:
cstuart11@protonmail.com
tranqc(1)
Tranquility
Programmer’s Manual
https://www.cs.drexel.edu/~bls96/tranquility.pdf