This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
HurdeHack's profile picture

[lua][question]keep the time ticking

Started by HurdeHack, 21 October 2012 - 01:59 PM
HurdeHack #1
Posted 21 October 2012 - 03:59 PM
hello im pretty long active here but im not an pro in lua scripting well anyway my question is is it possible to keep an time ticking i mean in a code
im dutch so dont look at translate faults XD
remiX #2
Posted 21 October 2012 - 05:13 PM
Yeah, you use for loops and if statements ;p
exploder #3
Posted 21 October 2012 - 05:19 PM
Yes, it is possible using a loop.

This is a basic 24 clock going on loop:
while true do – Here starts the loop
local time = os.time()
time = textutils.formatTime(time, true) – Replace true with false for 12- hour clock.
print("Time:"..time)
sleep(0.2) – We want to add sleep so computer doesn't throw error out after some time.
term.clear() – Clear screen so it's nice and clean
term.setCursorPos(1,1) – Set Cursor to starting point.
end

And this will make clock refresh every 0.2 second.