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

Need help with ingame clock

Started by Flipsanta, 15 December 2012 - 11:01 PM
Flipsanta #1
Posted 16 December 2012 - 12:01 AM
hello
i am new to computer craft and want to make a ingame clock with monitors.

i found this code, and put into a program called "clock", then a write monitor right clock(got my monitor on the right) and get this error: "textutils:30: attempt to compare function with number"

function infiniteLoop()
while true do
local time = os.time()
time = textutils.formatTime(time, false)
term.clear()
term.setCursorPos(1,1)
print(time)
sleep(0.8)
end
end
infiniteLoop()
remiX #2
Posted 16 December 2012 - 12:15 AM
Just use this:

Will print on computer terminal and monitor

monitorSide = "right"
mon = peripheral.wrap(monitorSide)

while true do
    term.clear()
    term.setCursorPos(1,1)
    mon.clear()
    mon.setCursorPos(1,1)
    print( textutils.formatTime( os.time() , false ) )
    mon.write( textutils.formatTime( os.time() , false ) )
    sleep(0.8)
end
theoriginalbit #3
Posted 16 December 2012 - 12:41 AM
Just use this:

Will print on computer terminal and monitor

monitorSide = "right"
mon = peripheral.wrap(monitorSide)

while true do
	term.clear()
	term.setCursorPos(1,1)
	mon.clear()
	mon.setCursorPos(1,1)
	print( textutils.formatTime( os.time() , false ) )
	mon.write( textutils.formatTime( os.time() , false ) )
	sleep(0.8)
end

term.clear() and term.setCursorPos(1,1) arent required…
Flipsanta #4
Posted 16 December 2012 - 12:45 AM
Just use this:

Will print on computer terminal and monitor

monitorSide = "right"
mon = peripheral.wrap(monitorSide)

while true do
	term.clear()
	term.setCursorPos(1,1)
	mon.clear()
	mon.setCursorPos(1,1)
	print( textutils.formatTime( os.time() , false ) )
	mon.write( textutils.formatTime( os.time() , false ) )
	sleep(0.8)
end

thanks, but i wrote it, and comes with this error: "bios:338: [string "clock"]:8: '=' expected"
the program is called clock
theoriginalbit #5
Posted 16 December 2012 - 12:59 AM
works fine for me…


also i suggest making the sleep no bigger than 0.4 or you will skip numbers sometimes as the computer never starts at the perfect time. (I've experimented till i found the right number)

the program is called clock

the error tells us this…