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

Window:57: Expected number

Started by PixelFox, 18 April 2015 - 11:19 AM
PixelFox #1
Posted 18 April 2015 - 01:19 PM
I get that error when ever I run this program.

function drawPixel(x, y, color)
term.setBackgroundColor(color)
term.togglePixel(x, y)
end
function drawDriveIcon(x, y, text)
  drawPixel(x, y, color)
  term.setCursorPos(x, y+2)
  term.setBackgroundColor(colors.white)
  term.setTextColor(colors.black)
  term.write(text)
end
function bufferBackground()
term.clear()
paintutils.drawLine(1, 1, 51, 1, colors.lightBlue)
paintutils.drawFilledBox(1, 2, 100, 100, colors.white)
end
bufferBackground()
drawDriveIcon(3, 3, "C:")
while true do
  local event, button, xPos, yPos = os.pullEvent()
  if event == "mouse_click" then
   
  end
end
Can you maybe explain, I bug tested it, and it leads me to the error being driven by term.togglePixel() but…I dunno why.
Bomb Bloke #2
Posted 18 April 2015 - 01:31 PM
The idea is that the window API is used by advanced computers to handle multishell's multiple tab system. This, in turn, leads to any mis-use of term API functions tending to error out in the window API instead.

"term.setBackgroundColor(color)" is where you're triggering the error - because "color" isn't a number, it's nil. You never set it to anything.

CC doesn't have a term.togglePixel function at all, so I'd expect an "attempt to call nil" on that third line - but you're currently crashing out before you get there.
PixelFox #3
Posted 18 April 2015 - 01:37 PM
The idea is that the window API is used by advanced computers to handle multishell's multiple tab system. This, in turn, leads to any mis-use of term API functions tending to error out in the window API instead.

"term.setBackgroundColor(color)" is where you're triggering the error - because "color" isn't a number, it's nil. You never set it to anything.

CC doesn't have a term.togglePixel function at all, so I'd expect an "attempt to call nil" on that third line - but you're currently crashing out before you get there.
What do you mean? term.togglePixel is a function! I saw it on an tutorial page! And color is set!
http://www.computercraft.info/forums2/index.php?/topic/3348-1415-pixel-manipulation/
Edited on 18 April 2015 - 11:38 AM
Bomb Bloke #4
Posted 18 April 2015 - 02:02 PM
Sorry, that link's not a tutorial - that's a suggestion, a request to have such a function added to ComputerCraft.

You can view the functions currently available in the "term" table here.

And color is set!

Where, exactly? Not in this script, it isn't.
Edited on 18 April 2015 - 01:21 PM
TheOddByte #5
Posted 18 April 2015 - 03:37 PM
The problem lies in your drawDriveIcon function, where you call the drawPixel function with the arguments x, y, color.
But the variable color isn't declared there, and that's how you're getting this error.
PixelFox #6
Posted 18 April 2015 - 03:44 PM
Sorry, that link's not a tutorial - that's a suggestion, a request to have such a function added to ComputerCraft.

You can view the functions currently available in the "term" table here.

And color is set!

Where, exactly? Not in this script, it isn't.
Oh. I made a typo in the code… :\
But I have a new problem. I got rid of that code.
Code:

function list(directory)
  local a
  local b
  a = fs.list(directory)
  for i=1, #a do
    if fs.isDir(a[i]) then
	 b[i] = "true"
    end
  end
  return a, b
end
I get:
Explorer:7: index expected, got nil
HPWebcamAble #7
Posted 18 April 2015 - 04:03 PM

function list(directory)
  local a
  local b
  a = fs.list(directory)
  for i=1, #a do
	if fs.isDir(a[i]) then
	 b[i] = "true"
	end
  end
  return a, b
end
I get:
Explorer:7: index expected, got nil

On the line where you define 'local b' change it to this:

local b = {}    --# Makes it an empty table

Lua won't let you try to use a nil variable like a table (hence the error)
PixelFox #8
Posted 18 April 2015 - 04:09 PM
Now I need to know:
How would I test if a file is a folder?
Bomb Bloke #9
Posted 18 April 2015 - 04:18 PM
By using a function from the fs API.
PixelFox #10
Posted 18 April 2015 - 04:26 PM
By using a function from the fs API.
Okay. But um…
is fs.isDir the one? I can't seem to use it.

function list(directory)
  local a
  local b = {}
  a = fs.list(directory)
  for i=1, #a do
	if fs.isDir(a[i]) then
	 b[i] = "true"
	else
	 b[i] = "false"
	 end
  end
  return a, b
end
b ALWAYS equals "true". Is there any fix?
Wait, nevermind.
Edited on 18 April 2015 - 02:52 PM
flaghacker #11
Posted 18 April 2015 - 07:19 PM
By using a function from the fs API.
Okay. But um…
is fs.isDir the one? I can't seem to use it.

function list(directory)
  local a
  local b = {}
  a = fs.list(directory)
  for i=1, #a do
	if fs.isDir(a[i]) then
	 b[i] = "true"
	else
	 b[i] = "false"
	 end
  end
  return a, b
end
b ALWAYS equals "true". Is there any fix?
Wait, nevermind.

Why are you using "true" instead of true? (string vs boolean)
Edited on 18 April 2015 - 05:19 PM
PixelFox #12
Posted 18 April 2015 - 10:20 PM
By using a function from the fs API.
Okay. But um…
is fs.isDir the one? I can't seem to use it.

function list(directory)
  local a
  local b = {}
  a = fs.list(directory)
  for i=1, #a do
	if fs.isDir(a[i]) then
	 b[i] = "true"
	else
	 b[i] = "false"
	 end
  end
  return a, b
end
b ALWAYS equals "true". Is there any fix?
Wait, nevermind.

Why are you using "true" instead of true? (string vs boolean)
Because, that "true" will become more then booleans. I'm using a strong to just, IDK, help me along so I don't have to create another table