4 posts
Posted 21 November 2012 - 01:37 AM
Hello, I am extremely new to coding on CC, and I am trying to code a doorlock with an alarm. I have taken all the coding I have read on the forums and compiled them into my brain to try and make this code work….But yet I have failed. When I attempt to run the code, It gives me an error. The error is " Bios:206: [string "startup"] :1: unexpected symbol"
My code is
local doorside = <right>
local alarmside = <back>
local password = "nacho"
local opentime = 5
while true do
term.clear()
term.setCursorPos(1, 1)
local pass = read("*")
if pass == password then
print("Password Correct")
print("Opening the door...")
rs.setOutput(alarmSide, false)
rs.setOutput(doorSide, true)
sleep(openTime)
rs.setOutput(doorSide, false)
else
print ("Password Invalid!")
print ("Alarm Activated!")
sleep (1)
rs.setOutput(alarmSide, true)
sleep (5)
os.reboot ()
2088 posts
Location
South Africa
Posted 21 November 2012 - 01:47 AM
Try this
local doorSide = "right" -- It needs " " just like you did with password
local alarmSide = "back"
local password = "nacho"
local opentime = 5
while true do
term.clear()
term.setCursorPos(1, 1)
local pass = read("*")
if pass == password then
print("Password Correct")
print("Opening the door...")
rs.setOutput(doorSide, true)
sleep(openTime)
rs.setOutput(doorSide, false)
else
print ("Password Invalid!")
print ("Alarm Activated!")
sleep (1)
rs.setOutput(alarmSide, true)
sleep (5)
os.reboot()
end -- You need to end the 'if' statement
end -- You need to end the 'while' loop
4 posts
Posted 21 November 2012 - 01:58 AM
Now it gave me Bios :206: [string "startup"] :9: unfinished string.
2088 posts
Location
South Africa
Posted 21 November 2012 - 02:09 AM
Tested it and it works for me…
I fixed a few spelling errors, if this doesn't work, then I it's something wrong with your CC.
local doorSide = "right" -- It needs " " just like you did with password
local alarmSide = "back"
local password = "nacho"
local openTime = 5
while true do
term.clear()
term.setCursorPos(1, 1)
print("Enter password")
pass = read("*")
if pass == password then
print("Password Correct")
print("Opening the door...")
rs.setOutput(doorSide, true)
sleep(openTime)
rs.setOutput(doorSide, false)
else
print ("Password Invalid!")
print ("Alarm Activated!")
sleep (1)
rs.setOutput(alarmSide, true)
sleep (5)
os.reboot()
end -- You need to end the 'if' statement
end -- You need to end the 'while' loop
4 posts
Posted 21 November 2012 - 02:21 AM
Well it says startup :8: attempt to call nil. But now it runs, and goes through all of the prints and then startup :23: attempt to call nil
Okay, fixed that issue as well. But now it just says all of the prints and blinks…..I am close to giving up..
818 posts
Posted 21 November 2012 - 02:29 AM
rewrite line 8, and actually spell correctly echo :(/>/>
2088 posts
Location
South Africa
Posted 21 November 2012 - 02:34 AM
Well it says startup :8: attempt to call nil. But now it runs, and goes through all of the prints and then startup :23: attempt to call nil
Okay, fixed that issue as well. But now it just says all of the prints and blinks…..I am close to giving up..
Blinks? What do you mean blinks? O.o
4 posts
Posted 21 November 2012 - 02:53 AM
Like the print scripts just flash. It has me so confused lol.
2088 posts
Location
South Africa
Posted 21 November 2012 - 04:03 AM
I still don't understand. Do you mean it prints something and then it gets cleared instantly?