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

How do I display text on a monitor?

Started by Ezrealbra, 26 June 2014 - 04:31 AM
Ezrealbra #1
Posted 26 June 2014 - 06:31 AM
Okay, I know what all you guys are thinking. "What the hell, this couldn't be easier…"
It probably is, but I have no idea how to do this. I've been trying different things out for hours.
The closest I got was printing the data I wanted in the format I wanted into the terminal (using print)
but I couldn't get that same data onto the monitor. Then I got the first line on the monitor using
mon.write but not the other lines. I know you can do new lines of code in different boxes using cursor
I want new lines, or multiples lines per rows of monitors instead of 1 line per row. If anyone
understands what I'm trying to do, please tell me how to do it correctly… Also, I'm using a 2 high by 3 wide
monitor with the tower on the right side.

The data I would like: (I would like the format to be accurate to that.)

Welcome to the bunker.
Elevator - Press shift to go downwards, space to go upwards.

Floor 1 - Armory and Smeltery
Floor 2 - Thaumcraft and Witchery
Floor 3 - Spawners and Storage

Is this possible? If not, what's the closest I can get to it?
Shnupbups #2
Posted 26 June 2014 - 08:14 AM

mon = peripheral.wrap("right")
term.redirect(mon) --+ Redirects Printing to 'mon' Object
print("Welcome to the bunker.")
print("Elevator - Press shift to go downwards, space to go upwards.")
print(" ")
print("Floor 1 - Armory and Smeltery")
print("Floor 2 - Thaumcraft and Witchery")
print("Floor 3 - Spawners and Storage")
term.restore()

That should work, assuming you replace "right" in the first row with whatever side the monitor is on relative to the computer.

Basically, what you are looking for here is term.redirect(). This function makes any output (drawing, writing, etc.) be displayed on a monitor until term.restore() is called.
Edited on 26 June 2014 - 06:14 AM
cdel #3
Posted 26 June 2014 - 09:00 AM

mon = peripheral.wrap("right")
term.redirect(mon) --+ Redirects Printing to 'mon' Object
print("Welcome to the bunker.")
print("Elevator - Press shift to go downwards, space to go upwards.")
print(" ")
print("Floor 1 - Armory and Smeltery")
print("Floor 2 - Thaumcraft and Witchery")
print("Floor 3 - Spawners and Storage")
term.restore()

That should work, assuming you replace "right" in the first row with whatever side the monitor is on relative to the computer.

Basically, what you arelooking for here is term.redirect(). This function makes any output (drawing, writing, etc.) be displayed on a monitor until term.restore() is called.

although that is correct, from my understand:


-- wrapping the peripheral
mon = peripheral.wrap("right")
-- setting the text scale
mon.setTextScale(1)
-- writing to the monitor
mon.write("Hello World!")
-- setting the cursor position
mon.setCursorPos(1, 3)
-- writing to the monitor.. again.
mon.write("How are you?")
theoriginalbit #4
Posted 26 June 2014 - 09:34 AM
-snip-
though line wrapping will only happen with Shnupbups100s solution due to the fact that line wrapping occurs in write (which print uses) not the mon.write / term.write.
cdel #5
Posted 26 June 2014 - 10:34 AM
-snip-
though line wrapping will only happen with Shnupbups100s solution due to the fact that line wrapping occurs in write (which print uses) not the mon.write / term.write.

good point, line wrapping never occured to me :)/>
Ezrealbra #6
Posted 26 June 2014 - 02:58 PM

mon = peripheral.wrap("right")
term.redirect(mon) --+ Redirects Printing to 'mon' Object
print("Welcome to the bunker.")
print("Elevator - Press shift to go downwards, space to go upwards.")
print(" ")
print("Floor 1 - Armory and Smeltery")
print("Floor 2 - Thaumcraft and Witchery")
print("Floor 3 - Spawners and Storage")
term.restore()

That should work, assuming you replace "right" in the first row with whatever side the monitor is on relative to the computer.

Basically, what you are looking for here is term.redirect(). This function makes any output (drawing, writing, etc.) be displayed on a monitor until term.restore() is called.
This worked, but I recieved 2 odd errors. Here are screen shots:
Startup: http://prntscr.com/3wopl9
Output on monitor: http://prntscr.com/3woq4q
theoriginalbit #7
Posted 26 June 2014 - 03:15 PM
welcome to ComputerCraft 1.6 and above.

make the following change to line #2

local oldTerm = term.redirect(mon)
and this change to line #10

term.redirect(oldTerm)
Ezrealbra #8
Posted 26 June 2014 - 03:23 PM
welcome to ComputerCraft 1.6 and above.

make the following change to line #2

local oldTerm = term.redirect(mon)
and this change to line #10

term.redirect(oldTerm)
Thank you so much!
Shnupbups #9
Posted 27 June 2014 - 07:44 AM
welcome to ComputerCraft 1.6 and above.

Eesh. Yeah, I'm a bit rusty.
LeotomasMC #10
Posted 29 June 2014 - 03:06 AM
type your program then do "monitor [side] [program name]"