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

Redpower bundle error

Started by Creator13, 16 July 2012 - 06:34 AM
Creator13 #1
Posted 16 July 2012 - 08:34 AM
I try to make a door lock, which has two Redpower lamps (red and green), that switch when the password is correct. So when the password is correct, the red lamp turns off, and the green, in combination with the door, turns on. after four seconds, they switch again so that red's turned on. Also, redhas to bun always when the door is closed, so even if the computer's turned off.

Now i wrote a program to do this, but it gives th following error:

bios:206: [string "lock"]:30: ')' expected to (close '(' at line 29)
I understand that there must be a peranthesis at line 30, but there is one.

This is the code (not completed yet, but i tested it before i added the lamp switch and it worked):

os.pullEvent = os.pullEventRaw
function clear()
	term.clear()
	term.setCursorPos(1,1)
end
triesLeft = 5
function tries()
	triesLeft = triesLeft - 1
	triesLeftText = tostring(triesLeft)
end
tries()
  
term.redirect(peripheral.wrap("right"))
	clear()
	print("Enter password to open")
term.restore()
clear()
write("Enter your password: ")
password = read("*")
if password == "MyPassword" then
	print("Password correct!")
	rs.setBundledOutput("back", colors.orange)
	rs.setBundledOutput("back"
	rs.getBundledOutput("back") - colors.white)
	sleep(4)
	rs.setBundledOutput("back", colors.white)
	rs.setBundledOutput("back"
	rs.getBundledOutput("back") - colors.orange)
else
	print("Password incorrect, try again")
end

I really dont understand why this error came, so i hope someone here would be able to help me.
Also, I'm not very good with Lua yet, because I only use it about 4 days, Although i have programmed earlier in BASIC(QB), and I understand Lua
ChunkeeMunkee #2
Posted 16 July 2012 - 09:38 AM
Hi Creator,

I know that this isn't really answering your question - more of an observation really - but you could cut out the bundled cable element altogether by simply using a single wire and splitting it, one goes to the green lamp and the door, whilst the other goes to the red lamp via a NOT gate. Solves your requirement for the re lamp to be on whilst the computer's off too.

Sorry if that's a bit vague, I've not dabbled in CC for a while and am just getting back into it all!

Hope that helps!
Creator13 #3
Posted 16 July 2012 - 09:42 AM
Thanks, this helps alot, I'm gonna do it this way. In fact, putting the switch in the code was an alternative to make the switch; I first tired to do it with gates but wasnt able to get that working :P/>/> .
Creator13 #4
Posted 16 July 2012 - 10:19 AM
I asked my dad, who can program in C, and he said to change the code this way:

os.pullEvent = os.pullEventRaw
function clear()
	    term.clear()
	    term.setCursorPos(1,1)
end
function tries()
	    triesLeft = triesLeft - 1
	    triesLeftText = tostring(triesLeft)
end
triesLeft = 5
tries()
 
term.redirect(peripheral.wrap("right"))
	    clear()
	    print("Enter password to open")
term.restore()
clear()
write("Enter your password: ")
password = read("*")
if password == "MyPassword" then
	    print("Password correct!")
	    rs.setBundledOutput("back", colors.orange)
	    white = rs.getBundledOutput("back") - colors.white   --Its now a variable...
  rs.setBundledOutput("back", white)	  --...used here.
	    sleep(4)
	    rs.setBundledOutput("back", colors.white)
	    orange = rs.getBundledOutput("back") - colors.orange --Here the same
  rs.setBundledOutput("back", orange)
else
	    print("Password incorrect, try again")
end
Now this program doesnt work well, but at least, it gives no error. And i dont care because I'm gonna use the NOR gate like ChunkeeMunkee said above.
Mtdj2 #5
Posted 16 July 2012 - 11:09 AM
The error was at line 28 or so, you missed a parenthesis ")" at the rs.setBundledOutput("back"
Else i think it would work.
Hope this helped.
PS: Remember to look a bit before and after the line mentioned in the report. Will help you alot.
Creator13 #6
Posted 16 July 2012 - 12:33 PM
I did, but the way i did it in the first program was the same way as I used in another program, which worked. It's also the way it's explained in the Interactive tutorial here on the forums and the error was at line 30, not 28 (I think you meant 29 by the way, at 28 is no mising parenthesis)