Function milliDelay(): Difference between revisions
Jump to navigation
Jump to search
Založena nová stránka s textem „{{DISPLAYTITLE:function milliDelay()}} Run a function after specified number of milliseconds. milliDelay() is non-blocking (following command in the script…“ |
No edit summary |
||
| Line 2: | Line 2: | ||
Run a function after specified number of milliseconds. milliDelay() is non-blocking (following command in the script is executed immediately, before the callback function). | Run a function after specified number of milliseconds. milliDelay() is non-blocking (following command in the script is executed immediately, before the callback function). | ||
<i>nil</i> delay(number <u> | <i>nil</i> delay(number <u>milliseconds</u>, function <u>callback</u>) | ||
=== Parameters === | === Parameters === | ||
<i>number</i> <u>milliseconds</u> how much the callback will be delayed | <i>number</i> <u>milliseconds</u> how much the callback will be delayed | ||
<i>function</i> <u>callback</u> function to execute | <i>function</i> <u>callback</u> function to execute | ||
| Line 16: | Line 16: | ||
logf("%d", from) | logf("%d", from) | ||
if(from > 0) then | if(from > 0) then | ||
delay( | delay(1000, function() | ||
countDown(from-1) | countDown(from-1) | ||
end) | end) | ||
Revision as of 18:18, 18 April 2017
Run a function after specified number of milliseconds. milliDelay() is non-blocking (following command in the script is executed immediately, before the callback function).
nil delay(number milliseconds, function callback)
Parameters
number milliseconds how much the callback will be delayed function callback function to execute
Return value
nil
Usage
-- logs counts down from 5 to 0
function countDown(from)
logf("%d", from)
if(from > 0) then
delay(1000, function()
countDown(from-1)
end)
end
end
countDown(5)
See also
- delay() to delay callback execution by seconds