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

"Attempt to call nil"; What am I doing wrong?

Started by TheGag96, 08 July 2012 - 04:10 AM
TheGag96 #1
Posted 08 July 2012 - 06:10 AM
Hi, I'm new to lua and ComputerCraft, and I have a good knowledge of Java. I thought the rs API's way of using bundled cable colors was very weird, so I attempted to make a very small API that would make setting colors true or false a lot easier.

Here it is:

function setColor(a,b,c)

if type(a) ~= "string" then return end
if type(:)/>/> ~= "int" then return end
if type(c) ~= "boolean" then return end

if c == true then

rs.setBundledOutput(a,B)/>/>

else

if colors.test(rs.getBundledOutput(a,B)/>/>) == true then
rs.setBundledOutput(a, rs.getBundledOutput(a) - B)/>/>
end

end

end

When I test this with:

gagcolors.setColor("back",colors.pink,false)
it just outputs "gagcolors:13: Attempt to call nil". "gagcolors" is the name of my API, by the way.

What am I doing wrong? Thanks!
archit #2
Posted 08 July 2012 - 08:33 AM
Did you load your api first before attempting to use it in a program?
Mtdj2 #3
Posted 08 July 2012 - 12:00 PM
Where did big B come from? Lua is a case sensitive language.
the corrected code:

function setColor(a,b,c)
if type(a) ~= "string" then return end
if type(:)/>/> ~= "int" then return end
if type(c) ~= "boolean" then return end
if c == true then
rs.setBundledOutput(a,B)/>/>
elseif colors.test(rs.getBundledOutput(a,B)/>/>) == true then
rs.setBundledOutput(a, rs.getBundledOutput(a) - B)/>/>
end
end
end
That should work, havent tested.
But according to the error, you have a function, valuable or something like that which doesnt exist, maybe the B.
Hope this helped.