Note that sleep rounds to 0.05th of a second, due to how ticks work.
Your first issue is that Monitors do not normally support the Print command -- that's causing the try-to-call-nil error. More seriously, there are issues with how monitors reset their cursors -- ie, not at all. Monitor.Write() does not automatically add a newline (and Monitors don't support it in write), so if you were handling things through a pile of prints, than redirecting the terminal output would be the way to go.
Code:
Mon = peripheral.wrap("right")
term.redirect(Mon)
Mon.setCursorPos(1,1)
while true do
local time = os.time()
time = textutils.formatTime(time, false)
print("")
print("")
print("")
print("")
print("The time is "..time)
print("")
print("")
print("")
print("")
sleep(0.85)
end
However, while you can work around this by redirecting text from the terminal, it's probably better to use Mon.Write() and reset the cursor -- this will give you a lot better control of the placement of the printed text, as well as avoiding a bit of needless overhead. It's also bad ettiquite to redirect the terminal when you don't absolutely have to.
Code:
Mon = peripheral.wrap("right")
while true do
local time = os.time()
time = textutils.formatTime(time, false)
Mon.clear()
Mon.setCursorPos(1,5)
Mon.write("The time is "..time)
sleep(0.85)
end
((You can change the text position to anywhere on the monitor : Mon.setCursorPos(4,2) will put it on the second line, as if the text had three spaces before it.))
What do you mean by not reset it's self. I've ran a clock program for 5-6 hours and its been fine.
By default, Monitor devices will not horizontally scroll, nor will they care about their pre-existing location. Combined with needing Monitor.Write(), and this can result in undesirable behavior. If you do not start a monitor loop with mon.SetCursor(x,y), the computer will set the text wherever it pleases. That can be on the top left corner, or it can be part of the display that doesn't exist. If you've tried printing to the monitor while testing already, it will almost always be somewhere useless.