4 posts
Posted 29 June 2012 - 09:38 PM
Hello, I want a password. I use the better code from this side:
Click me! So, that works to open a door. Now I want to add that: The computer is above the door. If the password is correct, it makes a redstone signal down for 2 sec. If the password is wrong, it gives a redstone signal up. What I have to add in the code so it does that 2 things?
1604 posts
Posted 29 June 2012 - 10:32 PM
What do you have so far? You should try doing it by yourself before asking for someone to do the work for you. You won't learn anything if you don't.
4 posts
Posted 29 June 2012 - 10:38 PM
Now I've tried it, thats my code:
local password = Blablabla
local opentime = 3
term.clear()
term.setCursorPos(1,1)
write("Password: ")
local input = red("*")
if input == password then
-term.clear()
-term.setCursorPos(1,1)
-print("Access granted!")
-rs.setOutput("bottom",true)
-sleep(opentime)
-rs.setOutput("bottom",false)
-os.reboot()
else
-tern,clear()
-term.setCursorPos(1,1)
-print("Access denied!")
-rs.setOutput("top",true)
-sleep(5)
-rs.setOutput("top",false)
-os.reboot()
!Instead of the - I wrote Spacebar!
I always get this Error:
bios:206: [string "startup"]:222: 'end' expected
(to close 'if' at line 7)
How do i fix that?
1604 posts
Posted 29 June 2012 - 10:42 PM
local password = Blablabla -- remember to put quotes (") around strings (like: "Blablabla")
local opentime = 3
term.clear()
term.setCursorPos(1,1)
write("Password: ")
local input == password then -- you mixed two lines here: should be "local input = read()" and "if input == password then"
term.clear()
term.setCursorPos(1,1)
print("Access granted!")
rs.setOutput("bottom",true)
sleep(opentime)
rs.setOutput("bottom",false)
os.reboot()
else
tern,clear() -- typo: should be term.clear()
term.setCursorPos(1,1)
print("Access denied!")
rs.setOutput("top",true)
sleep(5)
rs.setOutput("top",false)
os.reboot()
-- missing end here
Fixed code:
local password = "password here"
local opentime = 3
term.clear()
term.setCursorPos(1,1)
write("Password: ")
local input = read("*")
if input == password then
term.clear()
term.setCursorPos(1,1)
print("Access granted!")
rs.setOutput("bottom",true)
sleep(opentime)
rs.setOutput("bottom",false)
os.reboot()
else
term.clear()
term.setCursorPos(1,1)
print("Access denied!")
rs.setOutput("top", true)
sleep(5)
rs.setOutput("top",false)
os.reboot()
end
4 posts
Posted 29 June 2012 - 10:43 PM
Omg, I forgot the end XD
Thx for the help, it works :P/>/>