Jump to content




Centre Print


  • You cannot reply to this topic
3 replies to this topic

#1 koslas

  • Members
  • 62 posts
  • LocationChristchurch, New Zealand

Posted 06 August 2012 - 11:44 PM

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?

#2 ChiknNuggets

  • Members
  • 130 posts

Posted 07 August 2012 - 01: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))


#3 brett122798

  • Members
  • 300 posts
  • LocationIn the TARDIS at an unknown place in time.

Posted 07 August 2012 - 01:24 AM

View PostChiknNuggets, on 07 August 2012 - 01:21 AM, said:

<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?

#4 ChiknNuggets

  • Members
  • 130 posts

Posted 07 August 2012 - 01:25 AM

i did not put in those span crap lol ill re type it





3 user(s) are reading this topic

0 members, 3 guests, 0 anonymous users