I'm trying to make 2 kinds of monitors, 1 a rules board, I want to list rules but i want them all center aligned, but i do not know how to program this, does anyone know? and same for the Welcome monitor I'm trying to center that too and don't know programming for it...
Rule Board Monitor Setup:
mmmmm
mmmmm
mmmmm
mmmmm
Welcome Board Monitor Setup:
mmmmmmm
Sooner the better Thank You!
I'm trying to make my welcome sign center aligned on my 1 tall 7 long monitor that says Welcome to Quantum Paradox!.
I currently have:
mon = peripheral.wrap("bottom")
mon.setTextScale(2.5)
mon.write("Welcome to Quantum Paradox!")
How do I center align this text?
5 replies to this topic
#1
Posted 19 February 2014 - 01:12 AM
#2
Posted 19 February 2014 - 01:28 AM
Posts merged.
#3
Posted 19 February 2014 - 03:26 AM
First you need to know where the center is - the display size varies depending on the amount of monitor blocks used and the text scale. Record the current dimensions of the screen with a call to term.getSize() (available to your monitor peripheral, which has most everything the term API has):
Now if you half "x", then further subtract half the length of the text you wish to print (27 characters in this case; halves down to about 13), you know how far from the left of the display you want to start writing. Collect the current row of the screen we're on with term.getCursorPos(), put the cursor there with term.setCursorPos() and then write:
Now, this is fine for the purposes of just centering one line. But what if you want to do it on a regular basis? This is where a function would come in useful:
When "centerText" is called, the string you want to write gets temporarily stored in the variable "printThis". The function can get the length of that string by checking "#printThis".
local xsize,ysize = mon.getSize()
Now if you half "x", then further subtract half the length of the text you wish to print (27 characters in this case; halves down to about 13), you know how far from the left of the display you want to start writing. Collect the current row of the screen we're on with term.getCursorPos(), put the cursor there with term.setCursorPos() and then write:
local curCol,curRow = mon.getCursorPos()
mon.setCursorPos(xsize/2 - 13, curRow)
mon.write("Welcome to Quantum Paradox!")
Now, this is fine for the purposes of just centering one line. But what if you want to do it on a regular basis? This is where a function would come in useful:
local mon = peripheral.wrap("bottom")
mon.setTextScale(2.5)
local function centerText(printThis)
local xsize,ysize = mon.getSize()
local curCol,curRow = mon.getCursorPos()
mon.setCursorPos((xsize - #printThis) / 2, curRow)
mon.write(printThis)
mon.setCursorPos(1, curRow+1) -- Optional, but it may be handy to have the cursor
-- moved to the start of the next line automatically.
end
centerText("Welcome to Quantum Paradox!")
When "centerText" is called, the string you want to write gets temporarily stored in the variable "printThis". The function can get the length of that string by checking "#printThis".
Edited by Bomb Bloke, 19 February 2014 - 03:42 AM.
#4
Posted 19 February 2014 - 10:56 AM
Thank you it worked!
When I make a new monitor i have the exact same programming when i run it it says:
bios:206: [string g"welcome"]:7: ')' expected
Now I looked for missing parentheses and stuff, but it was exactly the same, i have 5 other computers throughout my world running same code, but this is the only one that doesnt work..
When I make a new monitor i have the exact same programming when i run it it says:
bios:206: [string g"welcome"]:7: ')' expected
Now I looked for missing parentheses and stuff, but it was exactly the same, i have 5 other computers throughout my world running same code, but this is the only one that doesnt work..
local mon = peripheral.wrap("bottom")
mon.setTextScale(2.5)
local function centerText(printThis)
local xsize,ysize = mon.getSize()
local curCol,curRow = mon.getCursorPos()
mon.setCursorPos((xsize = #printThis) / 2, curRow)
mon.write(printThis)
mon.setCursorPos(1, curRow+1)
end
centerText("Server Info!")
Edited by arch2978, 19 February 2014 - 03:46 PM.
#5
Posted 19 February 2014 - 04:20 PM
In line 7 you say 'xsize = #printThis'
Shouldn't that be 'xsize - #printThis'? That should work
Shouldn't that be 'xsize - #printThis'? That should work
#6
Posted 19 February 2014 - 07:34 PM
Yes the - worked thank you! stupid mistake on my part.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











