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

Colors :36: Too Few Arguments

Started by Arimus, 16 August 2013 - 05:28 AM
Arimus #1
Posted 16 August 2013 - 07:28 AM
Hi everyone,

This is really driving me crazy. Let me say first that I am very new to programming and computercraft.

My situation:

I have a monitor setup with a computer under it. Going into the right side of the computer is a bundled cable connected to level emitters from my applied energistics storage system. These emitters control mob spawners. Each color in the bundle represents a mob spawner. I am trying to show on screen a number of buttons which are shown either red or green to indicate if the spawner is on or not. I am using a button API to draw the buttons on screen. This API lets me set the state…perfect!

I am using the following code: (just test code for now)


os.unloadAPI("button")
os.loadAPI("button")
local mon = peripheral.wrap("top")
mon.clear()
							 
button.setMon("top")	 
 
function check(button, wireColor)
print("test")
if (colors.test (rs.getBundledInput("right"), colors.wireColor)) == true then
  button.setState(button, false)
else
  button.setState(button, true)
end
end
 
button.add("endermen", "Endermen", "toggle", 5, 5, 20, 8, colors.lime, colors.red, colors.white, endermen)
button.setState("endermen", false)
button.draw()
while true do
check("endermen", white)
sleep(60)
end

When I run this program I get the message "colors :36: too few arguments" and I can't for the life of me figure out what it is. There are probably other errors in this code but I don't get that far as the program stops just after the "print("test") statement.

Does anyone have any suggestions?

Thanks!!
LBPHacker #2
Posted 16 August 2013 - 08:14 AM
colors.wireColor might be nil. I don't see its declaraion anywhere. And, if you pass a nil argument as the last argument, it's like you haven't passed that argument at all. Lua logic.
nolongerexistant #3
Posted 16 August 2013 - 08:21 AM
if (colors.test (rs.getBundledInput("right"), colors.wireColor)) == true then
colors.wireColor doesn't exist. You just need:

if (colors.test (rs.getBundledInput("right"), wireColor)) == true then
And pass wireColor to the function like:

colors.red
colors.green
colors.blue
Tiin57 #4
Posted 16 August 2013 - 08:22 AM
You'll want to use "colors[wireColor]", not "colors.wireColor".
albrat #5
Posted 16 August 2013 - 08:36 AM
I know the problem… You are handing a "white" to the program as a varible… You should hand the varible "colors.white" to the function.


function check(button, wireColor)
print("test")
if (colors.test (rs.getBundledInput("right"), colors.wireColor)) == true then  --// you should use wireColor not colors.wireColor.
  button.setState(button, false)
else
  button.setState(button, true)
end
end

check("endermen", white)  --// You should send the colors.white here.


with these two changes the code should work.

Also white is not defined at all as a varible. so you program was handing a nil value to wireColor .

edit ::
Ah beaten to the chase… lol - I went to save my food from burning while posting.
Edited on 16 August 2013 - 06:37 AM
Arimus #6
Posted 16 August 2013 - 09:06 AM
Thanks guys much appreciated. I will check it out when I get home!
Arimus #7
Posted 16 August 2013 - 10:44 AM
I got this program working. Many thanks everyone!