5 posts
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")"
521 posts
Location
Stockholm, Sweden
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?
5 posts
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 ) )
105 posts
Posted 10 October 2012 - 01:03 AM
also formatTime(), but why don't you compare the output of os.time() instead of formatTime()?
5 posts
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
5 posts
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
105 posts
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
5 posts
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… ;)/>/>