Jump to content




Monitor text, make new lines?


15 replies to this topic

#1 Tusillody

  • New Members
  • 11 posts

Posted 15 July 2012 - 05:50 PM

So I'm working on a computer program for a server I play on, and its going to be in the spawn. So im setting up a rules function, and everything's working except for the fact, I cant use mon.print(" ")

All I can use for text is mon.write("") and I cant figure out how to make the text go to a new line. Keep in mind, this is a function in an ongoing program, not monitor right blah.

Can anyone help me?

#2 Ponder

  • New Members
  • 49 posts

Posted 15 July 2012 - 05:57 PM

I haven't read that much about monitors, but shouldn't mon.write ('n') do the trick?

#3 Tusillody

  • New Members
  • 11 posts

Posted 15 July 2012 - 06:03 PM

I thought it would, but when I have

mon.write ("Rule 1: n")

It shows a question mark. And when I have it outside of quotations, it throws an error.

#4 1lann

  • Members
  • 516 posts
  • LocationSeattle

Posted 15 July 2012 - 06:14 PM

View PostTusillody, on 15 July 2012 - 06:03 PM, said:

I thought it would, but when I have

mon.write ("Rule 1: n")

It shows a question mark. And when I have it outside of quotations, it throws an error.
I believe it's /n. Also why don't you use mon.setCursorPos?

Edit: dammit I was wrong again :P/> keep on getting the / and mixed up

#5 Tusillody

  • New Members
  • 11 posts

Posted 15 July 2012 - 06:17 PM

/n inside quotations just displays Rule 1: /n.
And /n outside, gives an error for trying to use arithmetic on a string.

And Because i have over 10 lines of rules, i was trying to make it seem a bit neater. But If nothing else works, Ill just try that :P/>

#6 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 15 July 2012 - 07:14 PM

The easier way would be to redirect the terminal output and then use print:
local mon = peripheral.wrap("<side>") -- I guess you already know this
term.redirect(mon) -- redirect the output to the monitor
print("Hello World!!") -- use print, write, and any function that uses the terminal, it will show in the minitor
term.restore() -- after printing everything, restore the output to the terminal

BTW, this is how the monitor program works.

#7 Tusillody

  • New Members
  • 11 posts

Posted 15 July 2012 - 07:26 PM

View PostMysticT, on 15 July 2012 - 07:14 PM, said:

The easier way would be to redirect the terminal output and then use print:
local mon = peripheral.wrap("<side>") -- I guess you already know this
term.redirect(mon) -- redirect the output to the monitor
print("Hello World!!") -- use print, write, and any function that uses the terminal, it will show in the minitor
term.restore() -- after printing everything, restore the output to the terminal

BTW, this is how the monitor program works.

Awesome! This will work perfect, thank you!

#8 bloodless2010

  • Members
  • 27 posts

Posted 15 July 2012 - 07:43 PM

If you want to make a new line, you could also use setCursorPos,
so for example, you would have

local mon = peripheral.wrap("<side>") -- I guess you already know this
term.redirect(mon) -- redirect the output to the monitor
print("Hello World!!") -- use print, write, and any function that uses the terminal, it will show in the minitor
term
.restore() -- after printing everything, restore the output to the terminal
as MysticT said, But if you want to make another line for rules example it would be like this:

local mon = peripheral.wrap("<side>")
term.redirect(mon)
mon.setCursorPos(1,1)
print("Rules:")
mon.setCursorPos(1,2) -- this sets it to the second line
print("1: No Griefing!")
term.restore()

and so forth, it should work, it's how I did it with mine. Goodluck!!

#9 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 15 July 2012 - 07:47 PM

View Postbloodless2010, on 15 July 2012 - 07:43 PM, said:

If you want to make a new line, you could also use setCursorPos,
so for example, you would have

local mon = peripheral.wrap("<side>") -- I guess you already know this
term.redirect(mon) -- redirect the output to the monitor
print("Hello World!!") -- use print, write, and any function that uses the terminal, it will show in the minitor
term
.restore() -- after printing everything, restore the output to the terminal
as MysticT said, But if you want to make another line for rules example it would be like this:

local mon = peripheral.wrap("<side>")
term.redirect(mon)
mon.setCursorPos(1,1)
print("Rules:")
mon.setCursorPos(1,2) -- this sets it to the second line
print("1: No Griefing!")
term.restore()

and so forth, it should work, it's how I did it with mine. Goodluck!!

And why don't you just do:
local mon = peripheral.wrap("<side>")
term.redirect(mon)
print("Rules:")
print("1: No Griefing!")
-- All the prints you want here
term.restore()
It would have the same effect, since print already moves the cursor to the next line.

#10 bloodless2010

  • Members
  • 27 posts

Posted 15 July 2012 - 07:49 PM

View PostMysticT, on 15 July 2012 - 07:47 PM, said:

View Postbloodless2010, on 15 July 2012 - 07:43 PM, said:

If you want to make a new line, you could also use setCursorPos,
so for example, you would have

local mon = peripheral.wrap("<side>") -- I guess you already know this
term.redirect(mon) -- redirect the output to the monitor
print("Hello World!!") -- use print, write, and any function that uses the terminal, it will show in the minitor
term
.restore() -- after printing everything, restore the output to the terminal
as MysticT said, But if you want to make another line for rules example it would be like this:

local mon = peripheral.wrap("<side>")
term.redirect(mon)
mon.setCursorPos(1,1)
print("Rules:")
mon.setCursorPos(1,2) -- this sets it to the second line
print("1: No Griefing!")
term.restore()

and so forth, it should work, it's how I did it with mine. Goodluck!!

And why don't you just do:
local mon = peripheral.wrap("<side>")
term.redirect(mon)
print("Rules:")
print("1: No Griefing!")
-- All the prints you want here
term.restore()
It would have the same effect, since print already moves the cursor to the next line.
Oh ok, I'm new to this I didn't know! Thanks! :P/>

#11 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 19 September 2012 - 05:57 PM

I have a question: can you do the following?

local function redirector(side)
  term.redrect(peripheral.wrap(side))
  local temp={}
  for k,v in pairs(term) do
    temp[k]=v
  end
  term.restore()
  return temp
end

and that will return a table of functions including the print one

#12 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 19 September 2012 - 06:15 PM

If you feel really abitious, you could write a whole new write function just for your program that automatically adds a new line break into your strings as you call back to it.

#13 GopherAtl

  • Members
  • 888 posts

Posted 19 September 2012 - 06:16 PM

there's no print function in the term, it's a global that just uses term's write and get/setCursorPos functions, so... nope, sorry

the print function isn't magic, though. You could implement your own easily enough...
function printTo(device,text)
  local lines={}
  --break into lines on ns
  --we add a n at the end, so it behaves like print and so the match can find the last line
  string.gsub(text.."n","(.-)n",function(v) lines[#lines+1]=v end)
  local _,row=device.getCursorPos()
  local _,height=device.getSize()
  for i=1,#lines do
	--write the line
	device.write(lines[i])
	--move to next row
	row=row+1
	--if this went off the screen, scroll
	if row>height then
	  row=height
	  device.scroll(1)
	end
	--set to start of next line
	device.setCursorPos(1,row)
  end
end

:edit2: note that this doesn't support tabs (t).

#14 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 19 September 2012 - 06:24 PM

Also, it would return the term api functions, wich don't change when you redirect, they are always the same.

#15 d0min8r3

  • Members
  • 4 posts
  • LocationPennsylvania, U.S.

Posted 20 October 2012 - 03:14 AM

You can actually just type;

x = 1
y = 1
function setPoint()
mon.setCursorPos(x,y)
end

setPoint()
mon.write"Hello, User!"
y = y+1
setPoint()
mon.write"This is the Next line!"

#16 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 20 October 2012 - 03:46 AM

What about using multiline strings?
mon.write [[
Rules
---------
1. Follow rule #2
2. Follow rule #3
3. Follow rule #1
]]






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users