Jump to content




Showing text in the middle of monitors (Advanced of course)


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

#1 Bloodmorphed

  • New Members
  • 1 posts

Posted 30 September 2015 - 05:46 AM

So far I have this:

m = peripheral.wrap("back")

m.clear()
mX,mY = m.getSize()
x = math.floor(mX/2) - math.floor(string.len("text")/2)
y = math.floor(mY/2) - math.floor(string.len("text")/2)
m.setTextScale(1)
m.setCursorPos(x, y)
m.write("Market")


#2 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 30 September 2015 - 03:51 PM

Please read this, specifically the section about posting a good question. You've left us to guess what you expect the program to do and what it's actually doing instead. Also, you haven't asked a question.

In your case, the problem is obvious - you're setting the cursor position based on the length of the string "text", then you're writing the string "Market". "Market" will never be centered as long as you position the cursor based on the string "text" instead of the string "Market".

#3 Exerro

  • Members
  • 801 posts

Posted 30 September 2015 - 03:52 PM

What's your problem?

This should work:
local width, height = term.getSize()
local function centreWrite( text )
	term.setCursorPos( math.floor( width / 2 - #text / 2 ) + 1, math.floor( height / 2 ) + 1 )
	term.write( text )
end
Just replace term with 'm' or whatever.

Edited by awsumben13, 30 September 2015 - 03:53 PM.






2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users