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

Displaying time that updates on a computer screen while running an OS

Started by corbett, 21 June 2013 - 02:57 PM
corbett #1
Posted 21 June 2013 - 04:57 PM
I am trying to figure out a way to display time at the top right of an OS for myself. The time needs to update every MC minute and not hinder other running inputs like icons and right clicking. Also I found this http://pastebin.com/5CnXU7sj and it wouldnt work for me. if you could get this to, that would be great! any ideas welcomed!
Lyqyd #2
Posted 22 June 2013 - 03:28 PM
Split into new topic.
theoriginalbit #3
Posted 22 June 2013 - 07:56 PM
Ok so I suggest, since you're doing clicking and such, so should already have a loop like this, just add some code like so


--# 0.8 is a Mincraft second
local timeRefresh = os.startTimer(0.8)
--# your main program loop
while true do
  local event, p1, p2, p3, p4, p5 = os.pullEvent()
  if event == "timer" and p1 == timeRefresh then
	--# update the time here
	timeRefresh = os.startTimer(0.8)
  end
end
this code will easily work in around your existing code where you are checking for the clicking.

Most other people will try and recommend you to use the parallel API… this API will work, but is not needed in this circumstance.

Also as for code to convert the time and day into time and a calendar, I've created a program called CCalendar which uses this information and outputs time and date. The program you found is a highly complicated process for something that shouldn't be that complicated. It also doesn't include leap years, I made sure to put them in CCalendar.
corbett #4
Posted 23 June 2013 - 03:34 AM
Ok so I suggest, since you're doing clicking and such, so should already have a loop like this, just add some code like so


--# 0.8 is a Mincraft second
local timeRefresh = os.startTimer(0.8)
--# your main program loop
while true do
  local event, p1, p2, p3, p4, p5 = os.pullEvent()
  if event == "timer" and p1 == timeRefresh then
	--# update the time here
	timeRefresh = os.startTimer(0.8)
  end
end
this code will easily work in around your existing code where you are checking for the clicking.

Most other people will try and recommend you to use the parallel API… this API will work, but is not needed in this circumstance.

Also as for code to convert the time and day into time and a calendar, I've created a program called CCalendar which uses this information and outputs time and date. The program you found is a highly complicated process for something that shouldn't be that complicated. It also doesn't include leap years, I made sure to put them in CCalendar.
ok im really confused on how to put that in. Here is the code i have http://pastebin.com/vjc3HGkg
its from a youtube video tut but i know how to do some stuff but im lost on this
theoriginalbit #5
Posted 23 June 2013 - 03:40 AM
ok im really confused on how to put that in. Here is the code i have http://pastebin.com/vjc3HGkg
its from a youtube video tut but i know how to do some stuff but im lost on this
Ahh I see, NDFJay's tutorial………….. doesn't his next "tutorial" cover putting time on the GUI? o.O

Just put if after the os.pullEventRaw, and instead of using
event == "timer" and p1 == timerRefresh
use
event == "timer" and button == timerRefresh
that way it will compare the ID of the timer that finished, with the ID of the one that you started. That will be the easiest way for you without rewriting/restructuring your code.
corbett #6
Posted 23 June 2013 - 04:05 AM
ok im really confused on how to put that in. Here is the code i have http://pastebin.com/vjc3HGkg
its from a youtube video tut but i know how to do some stuff but im lost on this
Ahh I see, NDFJay's tutorial………….. doesn't his next "tutorial" cover putting time on the GUI? o.O

Just put if after the os.pullEventRaw, and instead of using
event == "timer" and p1 == timerRefresh
use
event == "timer" and button == timerRefresh
that way it will compare the ID of the timer that finished, with the ID of the one that you started. That will be the easiest way for you without rewriting/restructuring your code.
he never got past episode 3
albrat #7
Posted 01 July 2013 - 06:35 AM
I have a little time display on my password server on my single player… (admittedly it updates intermittently not every minute)


function time()
cpx, cpy = term.getCursorPos()
term.setCursorPos(25,5)
local t = os.time()
print("Time: "..textutils.formatTime(t,false))
term.setCursorPos(cpx, cpy)
end

What I did to make this work with a listening server was to make the listen time 1 - with
 senderId, mess, distance = rednet.receive(1)
if senderId == nil then
   time()
   else
If I get a message it stops updating the time untill it deals with the server request. But if it has no message to deal with it continuously updates the time, (after the else is my entire program with an "end" statement added on the end to close that loop.

the update on this is 1 min, 1 min, 2 min, 1min, 1min, 2min. Due to the tick difference (currently)

Edit..
I changed the rednet.receive(1) to rednet.receive(0.8) and this makes the clock update every minute. This also makes my server response time much faster too when a client requests a login. (I can barely tell when someone logs in as the time continues to tick as normal)
Edited on 01 July 2013 - 06:26 AM