2,736
edits
Red Leader (talk | contribs) (→settimer(): Start docing) |
Red Leader (talk | contribs) (→settimer(): Finish doc) |
||
| Line 2,053: | Line 2,053: | ||
=== settimer() === | === settimer() === | ||
{{Nasal doc | {{Nasal doc | ||
|syntax = settimer(function, delta[, realtime]); | |syntax = settimer(function, delta[, realtime]); | ||
|source = {{flightgear file|src/Scripting/NasalSys.cxx|l=499|t=Part 1}} {{!}} {{flightgear file|src/Scripting/NasalSys.cxx|l=1286|t=Part 2}} | |source = {{flightgear file|src/Scripting/NasalSys.cxx|l=499|t=Part 1}} {{!}} {{flightgear file|src/Scripting/NasalSys.cxx|l=1286|t=Part 2}} | ||
|text = Runs the given function a specified amount of seconds after the current time. Returns <code>'''nil'''</code>. | |text = Runs the given function a specified amount of seconds after the current time. Returns <code>'''nil'''</code>. | ||
{{note|Improper use of <code>settimer()</code> may cause resource leaks. It is also highly recommended that the newer {{func link|maketimer}} should be used instead of this function.}} | |||
|param1 = function | |param1 = function | ||
|param1text = Mandatory function that will be called. It may be necessary to enclose code in an anonymous function (see example). | |param1text = Mandatory function that will be called. It may be necessary to enclose code in an anonymous function (see example). | ||
| Line 2,064: | Line 2,064: | ||
|param3 = realtime | |param3 = realtime | ||
|param3text = If 1 (true), "real time" will be used instead of "simulation time." Defaults to 0 (false). Note that if "simulation time" is used, the timer will not run while FlightGear is paused. | |param3text = If 1 (true), "real time" will be used instead of "simulation time." Defaults to 0 (false). Note that if "simulation time" is used, the timer will not run while FlightGear is paused. | ||
|example1 = var myFunc = func(){ | |||
print("Hello"); | |||
} | |||
settimer(myFunc, 2); # runs myFunc after 2 seconds | |||
|example2 = var sqr = func(a){ | |||
return a * a; | |||
} | |||
settimer(func(){ | |||
print(sqr(2)); # will print 4 after 2 seconds | |||
}, 2); | |||
}} | }} | ||