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

OS/GUI help.

Started by bigspaceballs, 08 March 2014 - 07:09 PM
bigspaceballs #1
Posted 08 March 2014 - 08:09 PM
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 on 08 March 2014 - 08:03 PM
CometWolf #2
Posted 08 March 2014 - 08:34 PM
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.
bigspaceballs #3
Posted 08 March 2014 - 09:07 PM
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 on 08 March 2014 - 08:09 PM
CometWolf #4
Posted 08 March 2014 - 10:47 PM
Your code should work fine, provided your image file is located in the root folder. Otherwise, you would have to write "pantheon/background".
bigspaceballs #5
Posted 08 March 2014 - 10:55 PM
Okay, thanks.