34 posts
Posted 12 December 2012 - 03:12 AM
How would you go about centering something in a computer eg:
print ("center these words")
How would you center the words in the middle of the computer screen?
98 posts
Posted 12 December 2012 - 03:23 AM
i think theres something in textutils API that can help you with this!
34 posts
Posted 12 December 2012 - 03:27 AM
i think theres something in textutils API that can help you with this!
I am working on a script/API myself :/
I was just wondering if there is some standard lua code that i can use rather than installing a secondary API.
98 posts
Posted 12 December 2012 - 03:45 AM
textutils is in LUA.
1 posts
Location
Australia
Posted 12 December 2012 - 05:07 AM
Come on, this is some pretty simple maths ;)/>
OK, here's a function that figures out what X coordinate to print a string at so that it's centred.
function findCentre(str)
local centreX = term.getSize()
centreX = (centreX - #str) / 2
if centreX > 0 then
return centreX+1 -- This +1 is not necessary, it's personal preference.
else
return 1
end
end
Can you figure out how to display your string AT that X coordinate? HINT:
http://computercraft...rm.setCursorPosNote: A string with an even number of characters can't really be centred properly…this MAY set off your OCD as it did mine.
87 posts
Location
Basement
Posted 12 December 2012 - 12:04 PM
Take a look at my some GUI functions I made.
http://pastebin.com/hLLjTfjzIf you don't understand what the functions do just pm me or ask here :)/>
With my funtions just do..
shell.run("GUI")
cPrint ("center these words")
Note the shell cmd may vary…
3790 posts
Location
Lincoln, Nebraska
Posted 12 December 2012 - 12:51 PM
local function writeC(string)
local tX, tY = term.getSize()
local b = string.len(string) / 2
local x = (tX / 2) - b
local y = tY / 2
term.setCursorPos(x, y)
write(string)
end
This function prints any string in the center of the screen.