This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Centering Text
Started by flaminsnowman99, 24 July 2012 - 01:12 AMPosted 24 July 2012 - 03:12 AM
How do i center text on a screen? I've done this before i just cant remember how i did it :)/>/>
Posted 24 July 2012 - 03:24 AM
Hmm.. Exact center would be
text = "Blah"
x, y = term.getSize()
term.setCursorPos(x/2/string.len(text), y/2)
print(text)
Posted 25 July 2012 - 11:52 AM
Would you have to retype that for each word or would a sentance work?
Posted 25 July 2012 - 07:40 PM
Since "blah" is defining a string, anything inside that "" should be printed, I think. I'm not a pro, and would love to know as well, but that's just my guess.
Posted 25 July 2012 - 07:55 PM
This is a pretty nice function which does the job :)/>/>
I did not make it.
Made by Nitrogenfingers
I did not make it.
Made by Nitrogenfingers
local w,h = term.getSize()
function printCentered(msg, height)
term.setCursorPos(w/2 - #msg/2, height)
term.write(msg)
end
Posted 26 July 2012 - 06:45 PM
@sjonky
Height won't work, you placed it at the Y coord which means it should be at that position.
Height won't work, you placed it at the Y coord which means it should be at that position.
x, y = term.getSize()
function cPrint(msg)
term.setCursorPos(x/2/string.len(msg), y/2)
write(msg)
end
That should be correct to do exact center.Posted 26 July 2012 - 08:52 PM
What is the string.len() command? I never heard of that before now….
Posted 26 July 2012 - 09:58 PM
Well string.len() returns the length of a string (string.len("String")).
Its within the Lua string library.
LINK
Its within the Lua string library.
LINK
Posted 27 July 2012 - 01:00 AM
oh, I was looking in the CC wiki, that's why I never saw that. I have been getting accustomed to CC specific code, but lua code is still lightyears out of my full grasp