Jump to content




line break on a monitor?


  • You cannot reply to this topic
4 replies to this topic

#1 Sombriofe

  • Members
  • 3 posts

Posted 29 June 2013 - 06: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?

#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 30 June 2013 - 01: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


#3 darkrising

  • Members
  • 234 posts
  • LocationScotland

Posted 30 June 2013 - 08: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


#4 Sombriofe

  • Members
  • 3 posts

Posted 01 July 2013 - 07:03 PM

View PostLyqyd, on 30 June 2013 - 01:19 AM, said:

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.

View Postdarkrising, on 30 June 2013 - 08:31 AM, said:

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.

#5 Sombriofe

  • Members
  • 3 posts

Posted 01 July 2013 - 07: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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users