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

Equally split Monitor/Screen

Started by orik1997, 18 April 2015 - 10:55 PM
orik1997 #1
Posted 19 April 2015 - 12:55 AM
I have recently started working with Monitors. My first goal was to complete a System that automaticly splits the screen in 5 equal parts and writes down the Elements inside a table. It worked when I split the screen equally in 2 Parts and it even worked with 5 when I had really small values for my Elements but now it doesn't work. This is my Code:

local monitor = peripheral.wrap("top")
local x,y = monitor.getSize()
monitor.setTextScale(1)
monitor.clear()
menuString = {"ID","X-Pos","Z-Pos","Holes","Tracked Block"}
for i=1,5,1 do
monitor.setCursorPos(((x/5)-((menuString):len())/2)*i,1)
monitor.write(menuString)
end
Creator #2
Posted 19 April 2015 - 01:03 AM
All of the draws occur prety much at the same place. Try revising setCursorPos. What exactly are you trying to achieve?
orik1997 #3
Posted 19 April 2015 - 01:23 AM
I want to create the heading of a table with 5 columns one for ID the other for the XPosition and so on.
KingofGamesYami #4
Posted 19 April 2015 - 02:12 AM

local monitor = peripheral.wrap("top")
local x,y = term.getSize()
monitor.setTextScale(1)
monitor.clear()
menuString = {"ID","X-Pos","Z-Pos","Holes","Tracked Block"}

local maxColumnLen = x/5
for i = 1, 5 do
	local thisColumStarts = x / 5 * (i-1) + 1
	monitor.setCursorPos( thisColumStarts + ( (maxColumnLen-#menuString[i])/2), 1 )
	monitor.write(menuString[i])
end

I did a little bit of math, can probably be simplified and looks bad if the string you gave it is greater than a fifth of the monitor width, but it's what you were trying to do (I think).