Posted 15 February 2013 - 01:56 PM
I have been trying to create a function like the following that will center text and print it.
function center(text, xoffset, yoffset)
if xoffset == nil then xoffset = 0 end
if yoffset == nil then yoffset = 0 end
len = string.len(text)
len = math.ceil(len / 2)
local x,y = term.getSize()
x = math.ceil((x / 2) - len + xoffset)
y = math.ceil((y / 2) - len + yoffset)
term.setCursorPos(x, y)
print(text)
end
When I run it, it doesn't allways work correctly. Would giving it negative numbers affect it and is there a more efficient way to do this?