computer craft monitor help

  • Please make sure you are posting in the correct place. Server ads go here and modpack bugs go here
  • The FTB Forum is now read-only, and is here as an archive. To participate in our community discussions, please join our Discord! https://ftb.team/discord

Quesenek

New Member
Jul 29, 2019
396
0
0
the program is running but it's not displaying anything.
Code:
Mon = peripheral.wrap("right")
 
while true do
    Mon.clear()
    Mon.setCursorPos(1,1)
    local time = os.time()
    time = textutils.formatTime(time, false)
    Mon.write("the time is "..time)
    sleep(.83)
end
Using your existing code simply take all of the empty writes and use the setCursorPos to set the position. Your existing code works but you cannot see it with the empty writes it pushes it off the screen.
You will also want to use the clear to remove the existing text or it will be just a jumbled mess.
 

gattsuru

Well-Known Member
May 25, 2013
364
103
68
Note that sleep rounds to 0.05th of a second, due to how ticks work.

Your first issue is that Monitors do not normally support the Print command -- that's causing the try-to-call-nil error. More seriously, there are issues with how monitors reset their cursors -- ie, not at all. Monitor.Write() does not automatically add a newline (and Monitors don't support it in write), so if you were handling things through a pile of prints, than redirecting the terminal output would be the way to go.

Code:
Mon = peripheral.wrap("right")
term.redirect(Mon)
Mon.setCursorPos(1,1)
while true do
  local time = os.time()
  time = textutils.formatTime(time, false)
  print("")
  print("")
  print("")
  print("")
  print("The time is "..time)
  print("")
  print("")
  print("")
  print("")
  sleep(0.85)
end

However, while you can work around this by redirecting text from the terminal, it's probably better to use Mon.Write() and reset the cursor -- this will give you a lot better control of the placement of the printed text, as well as avoiding a bit of needless overhead. It's also bad ettiquite to redirect the terminal when you don't absolutely have to.

Code:
Mon = peripheral.wrap("right")
while true do
  local time = os.time()
  time = textutils.formatTime(time, false)
  Mon.clear()
  Mon.setCursorPos(1,5)
  Mon.write("The time is "..time)
  sleep(0.85)
end

((You can change the text position to anywhere on the monitor : Mon.setCursorPos(4,2) will put it on the second line, as if the text had three spaces before it.))

What do you mean by not reset it's self. I've ran a clock program for 5-6 hours and its been fine.
By default, Monitor devices will not horizontally scroll, nor will they care about their pre-existing location. Combined with needing Monitor.Write(), and this can result in undesirable behavior. If you do not start a monitor loop with mon.SetCursor(x,y), the computer will set the text wherever it pleases. That can be on the top left corner, or it can be part of the display that doesn't exist. If you've tried printing to the monitor while testing already, it will almost always be somewhere useless.
 
  • Like
Reactions: Enigmius1

Neywiny

New Member
Jul 29, 2019
3
0
0
Since people here appear to know things, (although the thread may be too old) I have a question.
Does the sleep command work in monitors? on the computer it outputs a signal, wait 2 seconds, and turns it off; on the monitor it only turns it on.
 

Bomb Bloke

New Member
Jul 29, 2019
612
0
0
The sleep command makes the computer wait. The monitor just displays what the computer tells it to display, until such time as the computer tells it to display something else.
 

Neywiny

New Member
Jul 29, 2019
3
0
0
nit like that silly :p when I say monitor top door, following monitor <side> <program> <arguments>
 

Bomb Bloke

New Member
Jul 29, 2019
612
0
0
If you start a script that way, the script is still running on the computer. The computer is using the monitor to display things, but ultimately it's the computer running the script.

The "sleep()" function works the same regardless - it simply makes the script pause. Anything to do with something being turned off or on has nothing to do with that. The scripts in this thread are rigged to run until you manually terminate them.
 

Neywiny

New Member
Jul 29, 2019
3
0
0
Code:
rs.setOutput("top",true)
sleep(2)
rs.setOutput("top",false)
that's the code. it turns it on, then leaves it on. I even tried it where both before and after the sleep it said hello, but only one popped up.