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

Centre Print

Started by koslas, 06 August 2012 - 10:44 PM
koslas #1
Posted 07 August 2012 - 12:44 AM
I am currently making a OS with a GUI. What I would like to happen, is the GUI text is printed in the centre. Does anyone know how I would be-able to do this?
ChiknNuggets #2
Posted 07 August 2012 - 02:21 AM
This Should do it



local function center(str)
local width = term.getSize()
local x,y = term.getCursorPos()
term.setCursorPos((width-#str)/2,y)
return str
end

Then just Call it using
print(center(string here))
brett122798 #3
Posted 07 August 2012 - 02:24 AM
<p>This Should do it </p>
<br />
<div><span>
</span>
<div><span>local function center(str)</span></div>
<div><span>    local width = term.getSize()</span></div>
<div><span>    local x,y = term.getCursorPos()</span></div>
<div><span>    term.setCursorPos((width-#str)/2,y)</span></div>
<div><span>    return str</span></div>
<div><span>end</span></div>
<span>
</span></div>
<div> </div>
<div>Then just Call it using </div>
<div><span>
print(center(string here))
</span></div>
<div> </div>
Uhh.. English?
ChiknNuggets #4
Posted 07 August 2012 - 02:25 AM
i did not put in those span crap lol ill re type it