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

how do i create a constantly updating monitor

Started by edog813, 17 November 2016 - 09:54 PM
edog813 #1
Posted 17 November 2016 - 10:54 PM
hey so im using the time command with a monitor but i'm having trouble making it constantly update can someone help me
Lyqyd #2
Posted 18 November 2016 - 01:49 AM
Moved to Ask a Pro.
Twijn #3
Posted 18 November 2016 - 02:26 AM
Use a

while true do
to print the os.time() command.
KingofGamesYami #4
Posted 18 November 2016 - 02:46 AM
Don't forget to yield somewhere in that loop!
EveryOS #5
Posted 18 November 2016 - 02:20 PM
Don't forget to yield somewhere in that loop!
If you want it to constantly show time, queue an event before yielding
nikolay04 #6
Posted 18 November 2016 - 04:20 PM
Its accualy pretty easy

while true do
os.time()
sleep(0)
end

the sleep(0) makes it loop forever without stopping(if you leave the chunks it wil stop, or if you terminate it)

Also to run it on the monitor

monitor (side) (program)
Edited on 18 November 2016 - 03:22 PM
Lyqyd #7
Posted 18 November 2016 - 05:43 PM
When showing in-game time, you should sleep for 0.6 seconds at a minimum. The time doesn't change more often than that.
Bomb Bloke #8
Posted 20 November 2016 - 02:14 AM
Truth be told, sleep(0) yields for a twentieth of a second anyway - which happens to be how often the clock increments. This is because the timer events used by the sleep function can only be generated upon a server tick.

Manually queuing and instantly pulling your own events will indeed waste a lot of processor power.