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

Time on monitor.

Started by Cranium, 29 July 2012 - 03:05 PM
Cranium #1
Posted 29 July 2012 - 05:05 PM
I have been writing a code for a train schedules display, and I want the time to be displayed on the lower right hand corner, and have it update every 5 seconds. I also want the rest of the monitor to display the rest of the schedule, but so far, I can get the clock to display properly, but none of the other information I want to print will display. Does the os.time() command clear everything out? Code here:

-- screen functions
function newpage()
  mon.setCursorPos(1,1)
  mon.setTextScale(1)
  mon.write("RailNet Train Schedules")
end
function time()
  mon.setTextScale(2)
  mon.setCursorPos(27,9)
  mon.write(textutils.formatTime(os.time(),false))
end
-- end screen functions
rednet.open("bottom")
-- vars
mon = peripheral.wrap("top")
term.redirect(mon)
-- end vars

while true do
newpage()
time()
event, sender, msg = rednet.receive(5)
  if msg == "station" then

    os.reboot()
  elseif msg == "nil" then
    os.reboot()
  end
end

So far I haven't gotten any of the advanced features in there yet, but I plan on doing a lot more.
BigSHinyToys #2
Posted 29 July 2012 - 05:19 PM
that works on my system What is the size of the monitor ?? I am testing on a full size screen.

when a print or write goes past the bottom of the screen all test is scrolled . maybe you need to adjust the position you print the time
Cranium #3
Posted 29 July 2012 - 05:55 PM
I have a 4h x 7w screen.
Cranium #4
Posted 29 July 2012 - 05:58 PM
HAH! I just realized what I did wrong. Since the os.time() command clears the screen, I needed to have it before my newpage() function. Derp. got it now…
BigSHinyToys #5
Posted 29 July 2012 - 06:15 PM
i think i have your problem. You cant display different sized text on the screen at the same time.
this is how it looks all the same size


CODE
Spoiler

-- screen functions
function newpage()
    mon.setCursorPos(1,1)
    mon.write("RailNet Train Schedules")
end
function fTime()
    mon.setCursorPos(27,9)
    mon.write(textutils.formatTime(os.time(),false))
end
-- end screen functions
rednet.open("bottom")
-- vars
mon = peripheral.wrap("top")
mon.setTextScale(2)
-- term.redirect(mon) you dont need this
-- end vars
while true do
    newpage()
    fTime()
    event, sender, msg = rednet.receive(5)
    if msg == "station" then
	    os.reboot()
    elseif msg == "nil" then
	    os.reboot()
    end
end
you

shouldn't use time for the name of a function as it is a function already in lua so i renamed it fTime()
Cranium #6
Posted 29 July 2012 - 06:20 PM
Thanks for the tip, I'll keep that in mind. I just wish I could have it display different sizes… Oh well…