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

Monitor DIsplay (Mutiple lines, all centered)

Started by Jumbify, 27 July 2012 - 07:56 PM
Jumbify #1
Posted 27 July 2012 - 09:56 PM
I remeber coming across a program on this form that allowed me to type in multiple lines of text and then display that text on any monitor size, centered. Sence then I have not been able to find that program (Using search and wiki). Can someone direct me to a program that would do this?

Thanks.
sjele #2
Posted 27 July 2012 - 11:02 PM
Well witch line is centred depens on the with, so that would have to be changed in the code.

mon = peripheral.wrap("right")
mon.setCursorPos(x, 1)  -- X has to changed to what you need to make it centred.
mon.write("text")
mon.setCursorPos(x, 1) --^ has to be changed here.
mon.write("Text on line2")
Mmmmmmmm #3
Posted 27 July 2012 - 11:32 PM
Well witch line is centred depens on the with, so that would have to be changed in the code.

mon = peripheral.wrap("right")
mon.setCursorPos(x, 1)  -- X has to changed to what you need to make it centred.
mon.write("text")
mon.setCursorPos(x, 1) --^ has to be changed here.
mon.write("Text on line2")
Wrong. You can automatically centre code.

local w,h = term.getSize()

function printCentred( y, s )
	local x = math.floor((w - string.len(s)) / 2)
	term.setCursorPos(x,y)
	term.write( s )
end
Simply do this on a monitor.

EDIT: Here's a program that would do this.
local tArgs = { ... }

assert( #tArgs == 2,"Usage: <name> <monitor side=""> <text>" )

local mon = peripheral.wrap(tArgs[1])
input = tArgs[2]

local w,h = mon.getSize()

function printCentred( y, s )
	local x = math.floor((w - string.len(s)) / 2)
	mon.setCursorPos(x,y)
	mon.clearLine()
	mon.write( s )
end

printCentred ( h/2,tArgs[2] )
It works no matter what the size of the monitor is, too.
Jumbify #4
Posted 28 July 2012 - 02:29 AM
local tArgs = { ... }

assert( #tArgs == 2,"Usage: <name> <monitor side=""> <text>" )

local mon = peripheral.wrap(tArgs[1])
input = tArgs[2]

local w,h = mon.getSize()

function printCentred( y, s )
	local x = math.floor((w - string.len(s)) / 2)
	mon.setCursorPos(x,y)
	mon.clearLine()
	mon.write( s )
end

printCentred ( h/2,tArgs[2] )
It works no matter what the size of the monitor is, too.


How do I enter the text?

In the last program I used is was something like this:
{
"Line of text 1",
"line of text 2",
"and so on"
}
Is that correct?

Either way, thanks for fidning this for me, I really appreciate it.
Jumbify #5
Posted 28 July 2012 - 03:03 PM
local tArgs = { ... }

assert( #tArgs == 2,"Usage: <name> <monitor side=""> <text>" )

local mon = peripheral.wrap(tArgs[1])
input = tArgs[2]

local w,h = mon.getSize()

function printCentred( y, s )
	local x = math.floor((w - string.len(s)) / 2)
	mon.setCursorPos(x,y)
	mon.clearLine()
	mon.write( s )
end

printCentred ( h/2,tArgs[2] )
It works no matter what the size of the monitor is, too.


How do I enter the text?

In the last program I used is was something like this:
{
"Line of text 1",
"line of text 2",
"and so on"
}
Is that correct?

Either way, thanks for fidning this for me, I really appreciate it.

I tried your program and its giving me this error:
[string "mon_text"]:3: ')' expected

even though the program is exactly the same as you typed it.