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.
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Window:57: Expected number
Started by PixelFox, 18 April 2015 - 11:19 AMPosted 18 April 2015 - 01:19 PM
I get that error when ever I run this program.
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.
"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.
Posted 18 April 2015 - 01:37 PM
What do you mean? term.togglePixel is a function! I saw it on an tutorial page! And color is set!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.
http://www.computercraft.info/forums2/index.php?/topic/3348-1415-pixel-manipulation/
Edited on 18 April 2015 - 11:38 AM
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.
Where, exactly? Not in this script, it isn't.
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
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.
But the variable color isn't declared there, and that's how you're getting this error.
Posted 18 April 2015 - 03:44 PM
Oh. I made a typo in the code… :\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.
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
Posted 18 April 2015 - 04:03 PM
I get: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
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)
Posted 18 April 2015 - 04:09 PM
Now I need to know:
How would I test if a file is a folder?
How would I test if a file is a folder?
Posted 18 April 2015 - 04:26 PM
Okay. But um…By using a function from the fs API.
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
Posted 18 April 2015 - 07:19 PM
Okay. But um…By using a function from the fs API.
is fs.isDir the one? I can't seem to use it.b ALWAYS equals "true". Is there any fix?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
Wait, nevermind.
Why are you using "true" instead of true? (string vs boolean)
Edited on 18 April 2015 - 05:19 PM
Posted 18 April 2015 - 10:20 PM
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 tableOkay. But um…By using a function from the fs API.
is fs.isDir the one? I can't seem to use it.b ALWAYS equals "true". Is there any fix?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
Wait, nevermind.
Why are you using "true" instead of true? (string vs boolean)