Template:Nasal Closure Wrapper
Jump to navigation
Jump to search
var timers = [];
foreach(var delay; [2.0, 4.0, 8.0] ) {
#this declares an anonymous/unnamed function
(func(arg...)
{
var interval=delay;
var myTimer = maketimer(interval, func() {
print("Hello from the ", interval,"-second timer!");
}); # end of the embedded func
myTimer.start();
append(timers, myTimer);
})(); # this will directly invoke the unnamed function
} # end of the foreach loop
# kill all timers
maketimer(60, func() {
foreach(var t; timers)
t.stop();
});
The following template description is not displayed when the template is inserted in an article.
Goal
This template can be used insert a Nasal snippet with an example of a function using maketimer().
Usage
{{Nasal Closure Wrapper |variable= |vector=}}
All parameters are optional.
See also Nasal Loops#for, while, foreach, and forindex loops.
- variable
- Name of local variable for the
foreach()loop. - Defaults to
delay.
- vector
- Vector for the
foreach()loop. - Defaults to
[2.0, 4.0, 8.0].
Technical details
This template uses {{Nasal Anonymous Func}}