sleep
Pauses execution of the program for time seconds. As it waits for a fixed amount of ticks, time will automatically be rounded up to the nearest multiple of 0.05 seconds. If you are using coroutines or the parallel API, it will only pause execution of the current thread, not the whole program.
sleep Function | |
---|---|
Syntax sleep(
| |
Returns | nil |
API | BIOS globals |
Source | CC:Tweaked (source) |
|
|||
Prints "Hello", waits 2 seconds, and then prints "world!". | |||
Code | <nowiki>
print("Hello")
sleep(2)
print("world!")
</nowiki>
|
||
Output | <nowiki>Hello
world!</nowiki>
|
|
|||
Writes 100 random numbers, one every tick. | |||
Code | <nowiki>
for i = 1, 100 do -- Run this 100 times
local x, y = term.getCursorPos()
term.setCursorPos(1, y) -- Go back to the start of the line
term.clearLine()
write(math.random())
sleep(0.05)
end
</nowiki>
|