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

[Lua] [Error] Doorlock with alarm coding problems.

Started by echo89, 21 November 2012 - 12:37 AM
echo89 #1
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 ()

remiX #2
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
echo89 #3
Posted 21 November 2012 - 01:58 AM
Now it gave me Bios :206: [string "startup"] :9: unfinished string.
remiX #4
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
echo89 #5
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..
Doyle3694 #6
Posted 21 November 2012 - 02:29 AM
rewrite line 8, and actually spell correctly echo :(/>/>
remiX #7
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
echo89 #8
Posted 21 November 2012 - 02:53 AM
Like the print scripts just flash. It has me so confused lol.
remiX #9
Posted 21 November 2012 - 04:03 AM
I still don't understand. Do you mean it prints something and then it gets cleared instantly?