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

First program

Started by Cikadamate, 21 April 2012 - 10:48 PM
Cikadamate #1
Posted 22 April 2012 - 12:48 AM
So this is my first program. A door lock.
The problem is when I start up the terminal it says: bios:206: [string "startup"]:19: '=' expected

local password = "password"
local debug = "debugger"
term.clear()
term.setCursorPos(1,1)
write("Password: ")
local input = read("*")
if input == (password) then
term.clear()
term.setCursorPos(1,1)
print("Good idea!")
rs.setOutput("right", true)
sleep(4)
rs.setOutput("right", false)
os.reboot()
elseif input == debug then
exit()
else
term.clear()
term.setCursorPos(1,1)
print("Incorrect password!")
sleep(2)
os.reboot()

Does anyone know what I need to change?
Luanub #2
Posted 22 April 2012 - 12:59 AM
See inline notes

local password = "password"
local debug = "debugger"
while true do -- added infinte loop to keep the program running and give you a clean way to exit
term.clear()
term.setCursorPos(1,1)
write("Password: ")
local input = read("*")
if input == password then -- dont need the ()'s around password
term.clear()
term.setCursorPos(1,1)
print("Good idea!")
rs.setOutput("right", true)
sleep(4)
rs.setOutput("right", false)
os.reboot()
elseif input == debug then
--exit() -- Do you have a function named exit? if not this will not work there is no exit function in lua. I would place the script in a while loop and change this to break
break -- stop the loop
else
term.clear()
term.setCursorPos(1,1)
print("Incorrect password!")
sleep(2)
os.reboot()
end -- end the loop
Cikadamate #3
Posted 22 April 2012 - 01:10 AM
Thankyou for a quick response.