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

[Lua] [Error] lamp0:1: attempt to call nil

Started by Dahleytje, 30 November 2012 - 05:21 AM
Dahleytje #1
Posted 30 November 2012 - 06:21 AM
Hi, me again. I am setting up a system to enable/disable all lights in our building.
I've bumped onto this error: lamp0:1: attempt to call nil
The system works like this:

a program called Lamps, can either launch lamp1 or lamp0 by typing On or Off
lamp1 turns them on, and lamp0 turns them off.
I did manage to get lamp1 to work, but 0 seems to fail (I'm not that experienced yet ;P)

here is the code for lamp0:


curColor = getBundledInput("top")
term.clear()
term.setCursorPos(1,1)
print("All lamps turned off")
rs.setBundledOutput("top, colors.subtract(curColor))

The color I use for switching the lamps on or off is yellow, if that matters.
If more information is needed please post ;)/>

Thanks in advance!

EDIT: I forgot the rs. before getBundledInput which caused the program to crash

another problem: it is still not disabling the current running color.
OmegaVest #2
Posted 30 November 2012 - 06:52 AM
First thing I see, you never close your quotes, but I'm guessing this is a transcription, not the actual code. Otherwise. . . You could just set it to 0, instead of subtracting everything out.
Dahleytje #3
Posted 30 November 2012 - 06:53 AM
I managed to fix it in another way:


term.clear()
term.setCursorPos(1,1)
   print("All lamps disabled.")
	  rs.setBundledOutput("top", colors.subtract (rs.getBundledOutput("top"), colors.yellow) )
Dahleytje #4
Posted 30 November 2012 - 06:54 AM
First thing I see, you never close your quotes, but I'm guessing this is a transcription, not the actual code. Otherwise. . . You could just set it to 0, instead of subtracting everything out.

Oh wow, so actually:

white equals 1
and nothing equals zero?
OmegaVest #5
Posted 30 November 2012 - 06:55 AM
Yeah. 0 means no colors are active. 1 is white, 2 is magenta, 4 is orange, and so forth up the color scale in binary.


Oh, and good on you for figuring out your own syntax issues.
Dahleytje #6
Posted 30 November 2012 - 07:00 AM
:)/> thanks, appreciate that.

Alright so I'm going to try a test with that.

Thanks alot again!