1 posts
Posted 04 November 2012 - 03:26 PM
Alright currently, I have no clue what i was doing. I need to center my text per line,
I have a 2x3 monitors saying
Welcome to
Servername
but the Welcome to i can center by setting cursor position, but when i do it will the server name it isn't exactly centered.
839 posts
Location
England
Posted 04 November 2012 - 03:49 PM
that's probably because when you call print, it sets the cursor position to one more than the current y, but sets x to 1
try doing this:
--this function will print the text in the centre of the current line
local printcentred =
function(text)
local maxw, maxh = term.getSize() --screen dimensions
local curx, cury = term.getCursorPos() --cursor pos
term.setCursorPos((maxw-#text)/2,cury) --set it to the point where write will make the text centred
term.write(text) --write the text
term.setCursorPos(curx,cury+1) --return the cursor to the same position on the next line
end
local maxw, maxh = term.getSize() --screen dimensions
term.setCursorPos(1,math.floor(maxh/2))--set cursor to the start of the upper middle line
printcentred("Welcome To")--print centred on that line
printcentred("Server Name")--print centred on the next line
521 posts
Location
Stockholm, Sweden
Posted 04 November 2012 - 05:25 PM
that's probably because when you call print, it sets the cursor position to one more than the current y, but sets x to 1
try doing this:
--this function will print the text in the centre of the current line
local printcentred =
function(text)
local maxw, maxh = term.getSize() --screen dimensions
local curx, cury = term.getCursorPos() --cursor pos
term.setCursorPos((maxw-#text)/2,cury) --set it to the point where write will make the text centred
term.write(text) --write the text
term.setCursorPos(curx,cury+1) --return the cursor to the same position on the next line
end
local maxw, maxh = term.getSize() --screen dimensions
term.setCursorPos(1,math.floor(maxh/2))--set cursor to the start of the upper middle line
printcentred("Welcome To")--print centred on that line
printcentred("Server Name")--print centred on the next line
Let me just make a quick note here; you are showing him a function to print in the middle on the GUI, not on a monitor.
515 posts
Location
Australia
Posted 04 November 2012 - 11:07 PM
Use term.redirect Problem solved?
839 posts
Location
England
Posted 05 November 2012 - 11:44 AM
Let me just make a quick note here; you are showing him a function to print in the middle on the GUI, not on a monitor.
It will if you run it on the monitor, but if you really insist on a monitor specific version:
--this function will print the text in the centre of the current line of the monitor connected on the specified side
local monitorprintcentred = function(text, side)
local monitor = peripheral.wrap(side)
local maxw, maxh = monitor.getSize() --screen dimensions
local curx, cury = monitor.getCursorPos() --cursor pos
monitor.setCursorPos((maxw-#text)/2,cury) --set it to the point where write will make the text centred
monitor.write(text) --write the text
monitor.setCursorPos(curx,cury+1) --return the cursor to the same position on the next line
end
local monitor = peripheral.wrap("left") -- makes 'monitor' refer to the monitor on the left side
local maxw, maxh =monitor.getSize() --screen dimensions
monitor.setCursorPos(1,math.floor(maxh/2))--set cursor to the start of the upper middle line
monitorprintcentred("Welcome To","left")--print centred on that line
monitorprintcentred("Server Name","left")--print centred on the next line
That was only knocked together in about 5 minutes, and I was assuming most people knew about the monitor program since it's mentioned on the CC wiki(
http://computercraft...p?title=Monitor), as well as mentioned in the built in help program.