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

Time Displayed on a Monitor

Started by RagnarTheBlue, 24 September 2012 - 01:10 AM
RagnarTheBlue #1
Posted 24 September 2012 - 03:10 AM
Hi, I'm really new to computercraft and im trying to output the the CPU time on a monitor, I'll put in os.time() but then i dont know how to display the return value any help?
Zoinky #2
Posted 24 September 2012 - 08:20 AM

local time = os.time()
print(time)
Simple :P/>/>
Mtdj2 #3
Posted 24 September 2012 - 11:09 AM

local time = os.time()
print(time)
Simple :P/>/>
Well, let me fix that code completely for you:

mon = perpheral.wrap("IAmAStringYouShallReplaceWithTheMonitorSide")
while true do
local time = os.time()
mon.write(time)
end
Hope I helped.

EDIT: I just saw what Xfel wrote, and i realized it's mon.write(time)
Xfel #4
Posted 24 September 2012 - 11:41 AM
only that you can't call print on a moditor peripheral?
RagnarTheBlue #5
Posted 24 September 2012 - 09:20 PM
Thanks, but is there a way so that it constantly updates?
Mtdj2 #6
Posted 25 September 2012 - 04:33 PM
Thanks, but is there a way so that it constantly updates?
Yes, I did that. The
while true do
makes it update, and because of 'true' it loops infinetly.
Xfel #7
Posted 25 September 2012 - 04:45 PM
however, you should add a sleep(1) to your loop as it will be aborted if it doesn't sleep for some time.
Mtdj2 #8
Posted 25 September 2012 - 04:56 PM
however, you should add a sleep(1) to your loop as it will be aborted if it doesn't sleep for some time.
Xfel, you only need sleep(0.1), makes it update more frequently.
Xfel #9
Posted 25 September 2012 - 07:13 PM
Yes, but… how frequently does the time change?
Noodle #10
Posted 25 September 2012 - 10:03 PM
Yes, but… how frequently does the time change?
Hmm.. Every second, millisecond, minute, hour, etc.
Cloudy #11
Posted 26 September 2012 - 09:00 AM
But do you need to know that information? Technically it changes every 0.05 seconds, but do you need to the time down to 0.05 real life seconds?
KaoS #12
Posted 26 September 2012 - 01:25 PM
don't forget mon.clear() mon.setCursorPos(1,1) or you will end up with a messy display. your clock only needs to update every second, would you really need a split second display on a clock?
ChaddJackson12 #13
Posted 27 September 2012 - 01:15 AM

local side = "top"  -- change this
if peripheral.getType(side) ~= "monitor" then
    print("No monitor on that side")
    return -- Neatly exits the program
else
    local monitor = peripheral.wrap(side)
    term.redirect(monitor)
    end

Print(("The Current Time is: ") textutils.formatTime(os.time(),true)))
end
Not sure if that works well or not but you could try it.
RemoteMine #14
Posted 27 September 2012 - 03:01 AM
If you want real time. timeapi.org.

Simply do http.get(). I don't really mess around with http in CC but you could probably figure it out :P/>/>