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

Displaying time on monitor

Started by DJHEMING, 09 October 2012 - 10:14 PM
DJHEMING #1
Posted 10 October 2012 - 12:14 AM
Hey Guys :P/>/> First problem i have come across, Im making a monitor display the time on a loop with a "sleep(1)" and i want to display during 6:00AM - 6:00PM:

The time is XX:XX TT
Have a good day!

And during 6:00PM - 6:00AM"

The time is XX:XX TT
Have a good night!

I have got the time to change ever second with a loop and a "sleep(1)" so it changes but i cant do the day and night thing… Help?


repeat
monitor = peripheral.wrap("right")
monitor.setTextScale(3.5)
local nTime = os.time()
print( "The time is "..textutils.formatTime( nTime, false ) )
if (..textitils.fromatTime( nTime, false ) ) < ("6:00 PM")
then print ( "Have a good night!" )
if (..textitils.fromatTime( nTime, false ) ) < ("6:00 AM")
then print ( "Have a good day!" )
sleep(1)
term.clear()
term.setCursorPos( 1, 1 )
until nil


EDIT: I have the monitor on the right of the computer, if you want to change it, then change "monitor = peripheral.wrap("THE SIDE OF THE MONITOR")"
jag #2
Posted 10 October 2012 - 12:40 AM
Some miss-spelling
if (..textitils.fromatTime( nTime, false ) ) < ("6:00 PM")
it's textutils not textitils. You even spelled it right at line 5.

Now why are you doing this:
if (..textitils.fromatTime( nTime, false ) ) < ("6:00 PM")
the 2 dots before textutils/textitils?
DJHEMING #3
Posted 10 October 2012 - 12:59 AM
Some miss-spelling
if (..textitils.fromatTime( nTime, false ) ) < ("6:00 PM")
it's textutils not textitils. You even spelled it right at line 5.

Now why are you doing this:
if (..textitils.fromatTime( nTime, false ) ) < ("6:00 PM")
the 2 dots before textutils/textitils?


Yeah i have a habit of miss spelling stuff :P/>/>

The ".." is cause in the time.file in computercraft (When you type time on the computer) the code is:


local nTime = os.time()
print( "The time is "..textutils.formatTime( nTime, false ) )
Fatal_Exception #4
Posted 10 October 2012 - 01:03 AM
also formatTime(), but why don't you compare the output of os.time() instead of formatTime()?
DJHEMING #5
Posted 10 October 2012 - 01:12 AM
also formatTime(), but why don't you compare the output of os.time() instead of formatTime()?

If you enter "lua" then type "os.time()" it comes up with #.### and not ##:##XX
DJHEMING #6
Posted 10 October 2012 - 01:18 AM
!UPDATE!

This is what i have going now but its displaying both "Have a good day!" and "Have a good night!" below…



repeat
monitor = peripheral.wrap("right")
monitor.setTextScale(1)
local nTime = os.time()
print( "The time is "..textutils.formatTime( nTime, false ) )
if (textutils.formatTime( nTime, false ) ) < ("6:00 PM") then print ( "Have a good day!" )
else print ( "Have a good night!" )
if (textutils.formatTime( nTime, false ) ) < ("6:00 AM") then print ( "Have a good night!" )
else print ( "Have a good day!" )
end
end
sleep(1)
term.clear()
term.setCursorPos( 1, 1 )
until nil
Fatal_Exception #7
Posted 10 October 2012 - 03:14 AM
Give this a try:

monitor = peripheral.wrap("right") -- Moved the initialization out of the loop
monitor.setTextScale(1)

repeat  
  term.clear()  -- Moved to start of loop to handle case where cursor is somewhere weird to begin with
  term.setCursorPos( 1, 1 )
  local nTime = os.time()
  print( "The time is "..textutils.formatTime( nTime, false ) )

  if nTime < 18 and nTime > 6 then
	print("Have a good day!")
  else
	print("Have a good night!")
  end

  sleep(1)

until nil
DJHEMING #8
Posted 10 October 2012 - 05:11 AM
Give this a try:

monitor = peripheral.wrap("right") -- Moved the initialization out of the loop
monitor.setTextScale(1)

repeat  
  term.clear()  -- Moved to start of loop to handle case where cursor is somewhere weird to begin with
  term.setCursorPos( 1, 1 )
  local nTime = os.time()
  print( "The time is "..textutils.formatTime( nTime, false ) )

  if nTime < 18 and nTime > 6 then
	print("Have a good day!")
  else
	print("Have a good night!")
  end

  sleep(1)

until nil

Thank you so much man :P/>/> Yeah it was very basic but still… ;)/>/>