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

Door Lock.

Started by Platinum_Apple, 15 June 2012 - 09:42 PM
Platinum_Apple #1
Posted 15 June 2012 - 11:42 PM
Every time i run this code:


local side = "left"
local password = "bacon"
local opentime = 5
term.clear()
term.setCursorPos(1,1)
write("Password: ")
local input = read("*")
if input == (password) then
term.clear()
term.setCursorPos(1,1)
print("Password correct!")
rs.setOutput(side,true)
sleep(5)
rs.setOutput(side,false)
os.reboot()
else
term.clear()
term.setCursorPos(1,1)
print("Password incorrect!")
sleep(2)
os.reboot()
end

I get the "bios:206: [string "startup"]:10: '=' expected"
error.
Help?
Lyqyd #2
Posted 16 June 2012 - 01:07 AM
Well, for one thing, take password out of the parentheses. They're unnecessary there. You should probably also run that in an infinite loop, so that the computer doesn't have to reboot unnecessarily.
Bossman201 #3
Posted 16 June 2012 - 02:18 AM
Code works fine when I run it. Couple things I've noticed, though.

1. Use some kind of formatting.
2.
sleep(5) -- should be sleep(openTime)
3.
rs.setOutput(side, true)
rs.setOutput(side, false) --no sense in creating and keeping track of a variable you do not need, rs.setOutput("left", true) will do just fine.
Lyqyd #4
Posted 16 June 2012 - 09:46 AM
2.
sleep(5) -- should be sleep(openTime)
3.
rs.setOutput(side, true)
rs.setOutput(side, false) --no sense in creating and keeping track of a variable you do not need, rs.setOutput("left", true) will do just fine.

Um, pick one. He either should use variables declared at the top in both places, or neither. They're the same use case, so why are you suggesting using the variable in one place and taking it out in another?