Jump to content




Window:57: Expected number

computer lua command computer lua command

11 replies to this topic

#1 PixelFox

  • Members
  • 106 posts

Posted 18 April 2015 - 12: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.

#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 18 April 2015 - 12: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.

#3 PixelFox

  • Members
  • 106 posts

Posted 18 April 2015 - 12:37 PM

View PostBomb Bloke, on 18 April 2015 - 12:31 PM, said:

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.computerc...l-manipulation/

Edited by Lightning, 18 April 2015 - 12:38 PM.


#4 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 18 April 2015 - 01: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.

View PostLightning, on 18 April 2015 - 12:37 PM, said:

And color is set!

Where, exactly? Not in this script, it isn't.

Edited by Bomb Bloke, 18 April 2015 - 02:21 PM.


#5 TheOddByte

    Lazy Coder

  • Members
  • 1,607 posts
  • LocationSweden

Posted 18 April 2015 - 02: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.

#6 PixelFox

  • Members
  • 106 posts

Posted 18 April 2015 - 02:44 PM

View PostBomb Bloke, on 18 April 2015 - 01:02 PM, said:

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.

View PostLightning, on 18 April 2015 - 12:37 PM, said:

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

#7 HPWebcamAble

  • Members
  • 933 posts
  • LocationWeb Development

Posted 18 April 2015 - 03:03 PM

View PostLightning, on 18 April 2015 - 02:44 PM, said:

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)

#8 PixelFox

  • Members
  • 106 posts

Posted 18 April 2015 - 03:09 PM

Now I need to know:
How would I test if a file is a folder?

#9 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 18 April 2015 - 03:18 PM

By using a function from the fs API.

#10 PixelFox

  • Members
  • 106 posts

Posted 18 April 2015 - 03:26 PM

View PostBomb Bloke, on 18 April 2015 - 03:18 PM, said:

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 by Lightning, 18 April 2015 - 03:52 PM.


#11 flaghacker

  • Members
  • 655 posts

Posted 18 April 2015 - 06:19 PM

View PostLightning, on 18 April 2015 - 03:26 PM, said:

View PostBomb Bloke, on 18 April 2015 - 03:18 PM, said:

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 by flaghacker, 18 April 2015 - 06:19 PM.


#12 PixelFox

  • Members
  • 106 posts

Posted 18 April 2015 - 09:20 PM

View Postflaghacker, on 18 April 2015 - 06:19 PM, said:

View PostLightning, on 18 April 2015 - 03:26 PM, said:

View PostBomb Bloke, on 18 April 2015 - 03:18 PM, said:

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





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users