PrintCenter "BLAH"
it will print to the center of the screen i have tried to make an api that does this but didnt succeed so if someone successfully makes this pleease tell me :P/>/>
local w,h = term.getSize()
local text = "SomeRandomString"
term.setCursorPos(w-20,h-10)
print(text)
term.setCursorPos(1,1)
Change how much it's taking off of the width and height until you get it centered.It's easier to take the lenght of the screen to make it always center, so you don't have to try and change the value until it gets centered.Just mess around with:Change how much it's taking off of the width and height until you get it centered.local w,h = term.getSize() local text = "SomeRandomString" term.setCursorPos(w-20,h-10) print(text) term.setCursorPos(1,1)
function PrintCentered(sText)
local w, h = term.getSize()
local x, y = term.getCursorPos()
x = math.max(math.floor((w / 2) - (#sText / 2)), 0)
term.setCursorPos(x, y)
print(sText)
end
This prints the text centered, but only the first line. So if you give it a string longer than the screen width, it prints like the normal print.here is what i have so farIt's easier to take the lenght of the screen to make it always center, so you don't have to try and change the value until it gets centered.Just mess around with:Change how much it's taking off of the width and height until you get it centered.local w,h = term.getSize() local text = "SomeRandomString" term.setCursorPos(w-20,h-10) print(text) term.setCursorPos(1,1)
Try something like this:This prints the text centered, but only the first line. So if you give it a string longer than the screen width, it prints like the normal print.function PrintCentered(sText) local w, h = term.getSize() local x, y = term.getCursorPos() x = math.max(math.floor((w / 2) - (#sText / 2)), 0) term.setCursorPos(x, y) print(sText) end
local function PrintCenter(msg)
local msgLen = string.len(msg)
local screenWidth,_ = term.getSize()
local xCoords = tonumber(math.ceil((screenWidth / 2) - (msgLen / 2)))
local _,termY = term.getCursorPos()
term.setCursorPos(xCoords,termY)
print(msg)
return xCoords
end
function PrintCenter(msg)
msgLen = string.len(msg)
screenWidth,_ = term.getSize()
xCoords = tonumber(math.ceil((screenWidth / 2) - (msgLen / 2)))
_,termY = term.getCursorPos()
term.setCursorPos(xCoords,termY)
print(msg)
return xCoords
end
It's easier to take the lenght of the screen to make it always center, so you don't have to try and change the value until it gets centered. Try something like this:Just mess around with:Change how much it's taking off of the width and height until you get it centered.local w,h = term.getSize() local text = "SomeRandomString" term.setCursorPos(w-20,h-10) print(text) term.setCursorPos(1,1)
This prints the text centered, but only the first line. So if you give it a string longer than the screen width, it prints like the normal print.function PrintCentered(sText) local w, h = term.getSize() local x, y = term.getCursorPos() x = math.max(math.floor((w / 2) - (#sText / 2)), 0) term.setCursorPos(x, y) print(sText) end
It's easier to take the lenght of the screen to make it always center, so you don't have to try and change the value until it gets centered. Try something like this:Just mess around with:Change how much it's taking off of the width and height until you get it centered.local w,h = term.getSize() local text = "SomeRandomString" term.setCursorPos(w-20,h-10) print(text) term.setCursorPos(1,1)
This prints the text centered, but only the first line. So if you give it a string longer than the screen width, it prints like the normal print.function PrintCentered(sText) local w, h = term.getSize() local x, y = term.getCursorPos() x = math.max(math.floor((w / 2) - (#sText / 2)), 0) term.setCursorPos(x, y) print(sText) end
Awsome code works great. Two questions how can have the print out move a bit to the left or right. Also how can I get this to show off a monitor try some things did not work.
function printCen(msg)
w, h = term.getSize()
term.setCursorPos(w/2, h/2)
write(msg)
end
function printCen(msg, ycord)
w, h = term.getSize()
term.setCursorPos(w/2, ycord)
write(msg)
end
If you'd actually tried either of those, you'd know they don't work properly as they always print the message to the right of the centre.Or you could just do thisfunction printCen(msg) w, h = term.getSize() term.setCursorPos(w/2, h/2) write(msg) end
Always prints in the center of the screen
If you want to print in the center of a line thenfunction printCen(msg, ycord) w, h = term.getSize() term.setCursorPos(w/2, ycord) write(msg) end