←  Ask a Pro

ComputerCraft | Programmable Computers for Minecraft

»

OS/GUI help.

bigspaceballs's Photo bigspaceballs 08 Mar 2014

I need a some help on a program I am writing.
so am following this series of tutorials on how to create you own basic OS, and I have created the files, typed in the code and I get a message every time: "paintutils:92: attempt to get length of nil" and I have only written a small amount. I first created a title bar, and that showed up. Then I tried to add my paint file to it as a desktop background using paintutils, and it gives me that message, and I don't even have 92 lines of code yet! So I went and opened up the paintutils api file, went to line 92, and all that was there was "else"?
Here is my code (hopefully you can understand it):

-- Preload variables

slc = 0
tbarC = 8
tbartC = 1
backColor = 1
term.setBackgroundColor(backColor)
term.clear()

function titleBar() -- Draws the title bar at the top.
	   term.setCursorPos(1,1)
	  term.setBackgroundColor(tbarC)
	  term.setTextColor(tbartC)
	 term.clearLine()
	 term.setCursorPos(3, 1)
	 print("[Begin]")
end

function drawDesktop()
	  bground = paintutils.loadImage("main.bground")
	  paintutils.drawImage(bground,1,1)
	  titlebar()  
end

drawDesktop()

Edited by jonbrozich, 08 March 2014 - 09:03 PM.
Quote

CometWolf's Photo CometWolf 08 Mar 2014

idk what version you're using but on mine (1.58) line 91 is this
function drawImage( tImage, xPos, yPos )
for y=1,#tImage do --here
  local tLine = tImage[y]
  for x=1,#tLine do
   if tLine[x] > 0 then
    term.setBackgroundColor( tLine[x] )
    drawPixelInternal( x + xPos - 1, y + yPos - 1 )
   end
  end
end
end

Now, looking over the loadImage function, it does not error if the file doesn't exist. It simply returns nil, therefore chances are your bground variable is nil, because the file "main.bground" does not exist.
Quote

bigspaceballs's Photo bigspaceballs 08 Mar 2014

 CometWolf, on 08 March 2014 - 08:34 PM, said:

idk what version you're using but on mine (1.58) line 91 is this
function drawImage( tImage, xPos, yPos )
for y=1,#tImage do --here
  local tLine = tImage[y]
  for x=1,#tLine do
   if tLine[x] > 0 then
	term.setBackgroundColor( tLine[x] )
	drawPixelInternal( x + xPos - 1, y + yPos - 1 )
   end
  end
end
end

Now, looking over the loadImage function, it does not error if the file doesn't exist. It simply returns nil, therefore chances are your bground variable is nil, because the file "main.bground" does not exist.

I am using the newest beta, but my api looks exactly like yours. I checked, and the file does exist, but just to be sure, I renamed it just "background" and it still didn't work. I don't

know if this makes a difference, but I created a directory in the computer called "pantheon". Can it still load the api with it being in its own folder?
Edited by jonbrozich, 08 March 2014 - 09:09 PM.
Quote

CometWolf's Photo CometWolf 08 Mar 2014

Your code should work fine, provided your image file is located in the root folder. Otherwise, you would have to write "pantheon/background".
Quote

bigspaceballs's Photo bigspaceballs 08 Mar 2014

Okay, thanks.
Quote