This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
ShadowZenoX's profile picture

Cursor positions

Started by ShadowZenoX, 06 June 2012 - 08:06 PM
ShadowZenoX #1
Posted 06 June 2012 - 10:06 PM
I was wondering im making a program and i want to have like the name and version on the top middle and have on the bottom left corner some text of updates but idk the cord's to do that is there like a picture i can see? ._.
OmegaVest #2
Posted 06 June 2012 - 10:19 PM
Uhhhhhhh……

Oh, you're looking for the x and y of the screen size, and how to get subjective numbers from objective ones. Oh, well that is quite simple.

First, find the x and y with

x,y = term.getSize()

then, use said sizes to get middles by dividing each in half, then subtracting half of your header width to find the cursor start position.

For the bottom, make a good guess at what fraction you want to start at, then use that fraction alongside the x and y, should give you a good idea.
ShadowZenoX #3
Posted 06 June 2012 - 10:21 PM
ok i was hoping for a simple ansawr w/e xD
OmegaVest #4
Posted 07 June 2012 - 03:44 PM
Well, anyway, here is some sample code, because it bugged me that I was getting a bit brusque with my answers last night.

For the header:

xTot, yTot = term.getSize()
headerInf = "This is your header."  -- Change for what you want

xStat = xTot/2 - (#headerInf /2)
term.setCursorPos(xStat, 2)  -- Just a guess on layout, mind you.

term.write(headerInf)

For the bottom, honestly the easiest way would be to take line four of the above and make it this:


xStat = xTot * 3/4

then make a wrap-around function, with a section similar to this:


xMax = xTot-xStat

if #Update[i] > xMax then
   Update[i]["a"] = string.sub(Update[i], 1, xMax-1)
   Update[i] = string.sub(Update[i], xMax-1, #Update[i])
end


Of course, that's only a fragment of what it should be. I would finish it, but the recursion would kill my brain this early in the morning (for me, anyway).
Bossman201 #5
Posted 08 June 2012 - 02:24 AM
Screen size is 50 x 18.