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

[Lua] How To Break Lines On Monitors?

Started by SNWLeader, 23 January 2013 - 02:02 PM
SNWLeader #1
Posted 23 January 2013 - 03:02 PM
I wanted to know how to break lines between each print after I have setup the monitor = peripherals.wrap("Monitor Side").
Does anyone know how to do that other than the way of figureing out how much space is on the monitor and filling it with spaces?
dissy #2
Posted 23 January 2013 - 03:06 PM
You can put \n in the string (\n = newline) including at the end of each write.

monitor.write("Line one\nLine two")

Or set the cursor posistion between each write command
I don't believe \n works in print() - but could be mistaken.

Edit: Probably closer to what you are looking for:
monitor.write("Line one\n")
monitor.write("Line two\n")
monitor.write("and so on…\n")
Barnyard_Owl #3
Posted 23 January 2013 - 03:08 PM
You could write your own function to do it with monitor.setCursorPos(x,y), or just use monitor.setCursorPos(x,y) for each line.

So, the closest you'll get to breaking lines (to my knowledge) without making a function, is using monitor.setCursorPos(x,y).

http://computercraft.../wiki/Term_(API)

Note: Just saw dissy's post, and it'll probably work. I just have always used print (when trying to use \n) and never used monitors, so you could be as good as right.
dissy #4
Posted 23 January 2013 - 03:15 PM
Note: Just saw dissy's post, and it'll probably work. I just have always used print (when trying to use \n) and never used monitors, so you could be as good as right.

I only mentioned that because some people do something like this:

monitor = peripheral.wrap("left")
term.redirect(monitor)
write("This would be line 1 on the monitor\nThis would be line two\n")
print("This is line three \n and this is 3 also because \n doesn't work here")

term.restore()
SNWLeader #5
Posted 23 January 2013 - 05:01 PM
ya I figured just set the breaks manually using the setCursorPos(x,y) function.
remiX #6
Posted 23 January 2013 - 05:50 PM
You can put \n in the string (\n = newline) including at the end of each write.

monitor.write("Line one\nLine two")

Or set the cursor posistion between each write command
I don't believe \n works in print() - but could be mistaken.

Edit: Probably closer to what you are looking for:
monitor.write("Line one\n")
monitor.write("Line two\n")
monitor.write("and so on…\n")

Last time I checked the write for monitors does not accept \n for new lines.
theoriginalbit #7
Posted 23 January 2013 - 05:54 PM
Last time I checked the write for monitors does not accept \n for new lines.
No it doesn't… here are the 2 ways to do it


local mon = peripheral.wrap( <side> )
mon.setCursorPos(1,1)
mon.write( "Line one" )
mon.setCursorPos(1,2)
mon.write( "Line two" )

Or this method

local mon = peripheral.wrap( <side> )
term.redirect( mon )
print( "Line one" )
print( "Line two" )

-- then at the very end of the program
term.restore()
remiX #8
Posted 23 January 2013 - 05:56 PM
or make a new write function

mWrite(text)
 cx, cy = mon.getCursorPos()
 monitor.write(text)
 mon.setCursorPos(1, cy + 1)
end

something like that…