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?
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
[Lua] How To Break Lines On Monitors?
Started by SNWLeader, 23 January 2013 - 02:02 PMPosted 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?
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?
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")
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")
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.
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.
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()
Posted 23 January 2013 - 05:01 PM
ya I figured just set the breaks manually using the setCursorPos(x,y) function.
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.
Posted 23 January 2013 - 05:54 PM
No it doesn't… here are the 2 ways to do itLast time I checked the write for monitors does not accept \n for new lines.
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()
Posted 23 January 2013 - 05:56 PM
or make a new write function
something like that…
mWrite(text)
cx, cy = mon.getCursorPos()
monitor.write(text)
mon.setCursorPos(1, cy + 1)
end
something like that…