How to center text?
#1
Posted 05 March 2012 - 01:14 AM
#2
Posted 05 March 2012 - 01:18 AM
local x,y = term.getSize()
local x2,y2 = term.getCursorPos()
term.setCursorPos(math.round((x / 2) - (text:len() / 2)), y2)
write(text)
end
centerText("Hello World")
Wrote off the top of my head, but you get the idea />
Edit: derp
#3
Posted 05 March 2012 - 01:20 AM
Casper7526, on 05 March 2012 - 01:18 AM, said:
local x,y = term.getSize()
term.setCursorPos(math.round((x / 2) - (text:len() / 2)), y)
term.write(text)
end
centerText("Hello World")
Wrote off the top of my head, but you get the idea />
#4
Posted 05 March 2012 - 01:22 AM
#5
Posted 05 March 2012 - 01:24 AM
#6
Posted 05 March 2012 - 01:27 AM
local function centerText(text) local x,y = term.getSize() local x2,y2 = term.getCursorPos() term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2) write(text) end centerText("Hello World")
That works for me...
#7
Posted 05 March 2012 - 01:28 AM
Casper7526, on 05 March 2012 - 01:27 AM, said:
local function centerText(text) local x,y = term.getSize() local x2,y2 = term.getCursorPos() term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2) write(text) end centerText("Hello World")
That works for me...
#8
Posted 05 March 2012 - 01:31 AM
(edit: nvm i figured it out)
#9
Posted 08 July 2012 - 10:37 AM
ComputerCraftFan11, on 05 March 2012 - 01:28 AM, said:
Casper7526, on 05 March 2012 - 01:27 AM, said:
local function centerText(text) local x,y = term.getSize() local x2,y2 = term.getCursorPos() term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2) write(text) end centerText("Hello World")
That works for me...
#10
Posted 08 January 2013 - 03:52 AM
#11
Posted 08 January 2013 - 04:08 AM
local function centerTextXY(text) local w, h = term.getSize() term.setCursorPos(math.floor(w / 2 - text:len() / 2 + .5), math.floor(h / 2 + .5)) io.write(text) end
#12
Posted 08 January 2013 - 06:33 AM
w, h = term.getSize() term.setCursorPos(math.floor(w - #text)/2, yPos)
#13
Posted 11 January 2013 - 08:31 PM
Nevermind I found out why.
#14
Posted 05 November 2013 - 09:41 PM
#15
Posted 06 November 2013 - 01:53 AM
I'd recommend posting a new thread that explains exactly what it is you're trying to do, along with the code you're currently using to do it.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users