This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Time Displayed on a Monitor
Started by RagnarTheBlue, 24 September 2012 - 01:10 AMPosted 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?
Posted 24 September 2012 - 08:20 AM
local time = os.time()
print(time)
Simple :P/>/>Posted 24 September 2012 - 11:09 AM
Well, let me fix that code completely for you:Simple :P/>/>local time = os.time() print(time)
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)
Posted 24 September 2012 - 11:41 AM
only that you can't call print on a moditor peripheral?
Posted 24 September 2012 - 09:20 PM
Thanks, but is there a way so that it constantly updates?
Posted 25 September 2012 - 04:33 PM
Yes, I did that. TheThanks, but is there a way so that it constantly updates?
while true do
makes it update, and because of 'true' it loops infinetly.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.
Posted 25 September 2012 - 04:56 PM
Xfel, you only need sleep(0.1), makes it update more frequently.however, you should add a sleep(1) to your loop as it will be aborted if it doesn't sleep for some time.
Posted 25 September 2012 - 07:13 PM
Yes, but… how frequently does the time change?
Posted 25 September 2012 - 10:03 PM
Hmm.. Every second, millisecond, minute, hour, etc.Yes, but… how frequently does the time change?
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?
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?
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.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/>/>
Simply do http.get(). I don't really mess around with http in CC but you could probably figure it out :P/>/>