1 posts
Posted 30 September 2015 - 06: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")
1220 posts
Location
Earth orbit
Posted 30 September 2015 - 04: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".
797 posts
Posted 30 September 2015 - 04: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 on 30 September 2015 - 02:53 PM