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

line break on a monitor?

Started by Sombriofe, 29 June 2013 - 05:13 PM
Sombriofe #1
Posted 29 June 2013 - 07:13 PM
Title: line break on a monitor?

Okay guys,

I'm usually a lurker here, but I'm trying to find if there is a way to inject a line break in my monitor coding.
I'm using a very simple code with a dedicated computer to post rednet messages on a 4x3 monitor next to it…

local monitor = peripheral.wrap("left")
rednet.open("right")
while true do
  event, id, text = os.pullEvent()
  if event == "rednet_message" then
	monitor.write(id..">"..text)
  end
end

I'm new to coding in CC and probably have bad code ettiquet, so I apologize for that.

The current program is a startup program so I don't have to do anything other than glance, but the problem is that it currently writes things as:
32>Hello World!36>Hello World!

obviously that is a bit confusing. I know about clearLine() and clear() commands, but that might make me miss something I would like to see. I understand I could define a setCursorPos(x,y) but then multiple messages might be overwritten or lost.
Does anyone have an idea about how I can go about making this work? Or is this just not implemented in the current coding yet?
Lyqyd #2
Posted 30 June 2013 - 02:19 AM
Split into new topic.

Wouldn't it be easier to just redirect the terminal to the monitor and use print?


local monitor = peripheral.wrap("left")
rednet.open("right")
while true do
    event, id, text = os.pullEvent()
    if event == "rednet_message" then
        term.redirect(monitor)
        print(id..">")
        print(text)
        term.restore()
    end
end
darkrising #3
Posted 30 June 2013 - 09:31 AM
Could try:

local monitor = peripheral.wrap("left")
mx, my = monitor.getSize()
rednet.open("right")
while true do
  event, id, text = os.pullEvent()
  if event == "rednet_message" then
	_,y = monitor.getCursorPos()
	monitor.write(id..">"..text)
    if y > my then y = my - 1 end
    monitor.setCursorPos(1, y + 1)
  end
end
Sombriofe #4
Posted 01 July 2013 - 08:03 PM
Wouldn't it be easier to just redirect the terminal to the monitor and use print?


local monitor = peripheral.wrap("left")
rednet.open("right")
while true do
	event, id, text = os.pullEvent()
	if event == "rednet_message" then
		term.redirect(monitor)
		print(id..">")
		print(text)
		term.restore()
	end
end

I see what you did there, but does it solve the line break issue? I saw that print would work, but figured write would be just as easy. Guess it was just a choice though I will give it a shot and see if it changes anything.

Could try:

local monitor = peripheral.wrap("left")
mx, my = monitor.getSize()
rednet.open("right")
while true do
  event, id, text = os.pullEvent()
  if event == "rednet_message" then
	_,y = monitor.getCursorPos()
	monitor.write(id..">"..text)
	if y > my then y = my - 1 end
	monitor.setCursorPos(1, y + 1)
  end
end

If you don't mind me asking why

 _,y = monitor.getCursorPos()


does the _ let the program skip the value of x? I also want to apologize if I didn't see the command of:


mx, my = monitor.getSize()

I probably wouldn't have thought of that either as I'm somewhat new to CC, and programming in general. I understand how programming works, and can do some of the coding in my head (son of an Engineer), but have never actually got off my butt and used the programming for anything. All my programming books act as dust magnets on my shelves, and I'm deeply, deeply ashamed to admit that.

I will let you know how this works after a little bit of testing tonight.
Sombriofe #5
Posted 01 July 2013 - 08:33 PM
Thank you both for your ideas. I have just completed testing them both, and they both allowed for line breaks. darkrising's idea though allows for if the monitor gets enough messages that they start falling off the screen. I believe I will use an amalgamation of the two and see if I can't progress from there.

Again thank you both.