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

[Lua][Error] Home security script!

Started by Helixon, 03 January 2013 - 05:22 AM
Helixon #1
Posted 03 January 2013 - 06:22 AM
Hi there,

I'm trying to build a home security script in computercraft (lua), but I cant get it to work.
I have tried to google it, even tried to write it all over, but still no luck.

With this script:

while true do

if colours.test(rs.getBundledInput("top", colours.purple)) then

alarmSensors()

end

sleep(0.5)
if (rs.getInput("front")) then break end

end

function alarmSensors()

	if(colours.test(rs.getBundledInput("right"), colours.red) || colours.test(rs.getBundledInput("right"), colours.green)) then
		rs.setBundledOutput("right", colours.lime)
		rs.setBundledOutput("top", colours.cyan)
		sleep(30)
	else
	   print("Building secure")
	end

end

i get the following error:


bios:206: [string "protect"]:16: ' ) ' expected

I hope you guys can help me out.

Thanks in advance,

Dean
Lyqyd #2
Posted 03 January 2013 - 06:35 AM
|| should be: or

Your function needs to be above your main loop.
Helixon #3
Posted 03 January 2013 - 07:45 AM
Hi Lyqyd,

i edited like you said, but it doesn't work eighter…


function alarmSensors()

	if(colours.test(rs.getBundledInput("right"), colours.red) or colours.test(rs.getBundledInput("right"), colours.green)) then
		rs.setBundledOutput("right", colours.lime)
		rs.setBundledOutput("top", colours.cyan)
		sleep(30)
	else
	   print("Building secure")
	end

end

while true do

if colours.test(rs.getBundledInput("top", colours.purple)) then

alarmSensors()

end

sleep(0.5)
if (rs.getInput("front")) then break end

end

now i get the following error:


bit:40: bad argument: double expected, got nil.


any suggestions?

regards,

Dean
Lyqyd #4
Posted 03 January 2013 - 08:36 AM
Check to make sure your colors have the correct names. I'm unsure, but purple may need to be violet.
Helixon #5
Posted 03 January 2013 - 01:07 PM
Check to make sure your colors have the correct names. I'm unsure, but purple may need to be violet.

Changed it, but no success……
ChunLing #6
Posted 04 January 2013 - 06:28 AM
Purple is colors.purple, according to the wiki. But use the lua program to go and check your colours table using "for k,v in pairs(colours) do print(k..": "..type(v)) end" so that you can make sure that the colours table is intact. Or type in print(colours.purple) and do that for all the colors you use in your program.

If none of your colours you use have been set to nil somehow or other, well…something funny must have happened to one or more of the api functions you're using.