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

Making a monitor

Started by NeeFoo, 30 August 2012 - 01:45 AM
NeeFoo #1
Posted 30 August 2012 - 03:45 AM
So as the title states, im making a monitor which is 5x3
but it produces the error ":9: attempt to get length of nil"
i've played around with line 9 but i cant get it to work :/

This is the code:

local tText = {
"random gibberish"
}
local sSide = "right"
local nTextSize = 2
local function printCenter(mon, t)
  local w, h = mon.getSize()
  local y = math.floor((h / 3) - (#t / 3)) - 1
  for i, line in ipairs(t) do
		local x = math.floor((w / 5) - (#line / 5))
		mon.setCursorPos(x, y + i)
		mon.write(line)
  end
end
local mon = peripheral.wrap(sSide)
mon.setTextScale(nTextSize)
printCenter(mon, tText)

please help me! :)/>/>
Luanub #2
Posted 30 August 2012 - 03:57 AM
For some reason t is nil. Its probably because you are passing the entire table to printCenter() function which is not going to work.

Try changing the last line to

printCenter(mon, tText[1])

and see if that works. If so you will have to figure out a way to let the script know which portion of the table you want to print.
NeeFoo #3
Posted 30 August 2012 - 04:04 AM
now its producing ":19: attempt to index ? (a nil value)"
Grim Reaper #4
Posted 30 August 2012 - 04:08 AM
Strangely enough, I copied the exact code you posted and ran into on a computer in my world; it executed exactly as it was written.

luanub, passing a string when a table is expected will only further scramble or complicate the results. I put it on my pastebin, from there I downloaded it onto a computer in my world and it ran just fine.

Try downloading it via pastebin to a computer in game:

pastebin get 6XUyapdm test
NeeFoo #5
Posted 30 August 2012 - 04:36 AM
what could be wrong? o.O
still getting the same error.. :/
NeeFoo #6
Posted 30 August 2012 - 04:55 AM
got it to work(placed the computer wrong-.-)

But now i have another problem.. the text wont center correctly.. it appears slightly to the top-left side