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

Help with code

Started by AwesomePwningGuy, 04 November 2012 - 03:05 AM
AwesomePwningGuy #1
Posted 04 November 2012 - 04:05 AM
This is my start up code for a password door.I need help it won't work.Sorry if under wrong section I'm new.

pass = 1337

print("Awesome Pwning Guy protected")
sleep(1)
print ("Enter password")
write "Password: "
input = read()
if input == pass then
print("Correct password")
sleep(1)
print("Access granted")
sleep(2)
redstone.setOutput("right", true)
sleep(4)
redstone.setOutout("right", false)
else
print("Password Incorrect")
redstone.setOutput("back, true)
sleep(4)
redstone.setOutput("back, true)

Error
bios:338: [string "startup"]:20: 'end' expected (to
close 'if' at line 8
sjele #2
Posted 04 November 2012 - 04:23 AM
if statements require an end. Your if on line 8 has no end.

Fixed code


pass = 1337
print("Awesome Pwning Guy protected")
sleep(1)
print ("Enter password")
write "Password: "
input = read()
if input == pass then
print("Correct password")
sleep(1)
print("Access granted")
sleep(2)
redstone.setOutput("right", true)
sleep(4)
redstone.setOutout("right", false)
else
print("Password Incorrect")
redstone.setOutput("back", true) --You forgot to close brackets here
sleep(4)
redstone.setOutput("back", true) --and here
end -- You need this
AwesomePwningGuy #3
Posted 04 November 2012 - 04:40 AM
Sorry for my fail thanks sjele. Lol that is why you don't trust me to coding.
AwesomePwningGuy #4
Posted 04 November 2012 - 04:52 AM
New error

startup:20: attempt to call nil
Pharap #5
Posted 04 November 2012 - 05:01 AM
New error

startup:20: attempt to call nil
do you have a copy of the new code?
AwesomePwningGuy #6
Posted 04 November 2012 - 05:03 AM
Same code as sjele fix version.


pass = 1337
print("Awesome Pwning Guy protected")
sleep(1)
print ("Enter password")
write "Password: "
input = read()
if input == pass then
print("Correct password")
sleep(1)
print("Access granted")
sleep(2)
redstone.setOutput("right", true)
sleep(4)
redstone.setOutout("right", false)
else
print("Password Incorrect")
redstone.setOutput("left", true)
sleep
(4)
redstone.setOutput("left", true)
end


note redstone torch is on left side.
Pharap #7
Posted 04 November 2012 - 05:12 AM
After looking in depth, I found a few errors, this should fix them all:

pass = "1337"
print("Awesome Pwning Guy protected")
sleep(1)
print("Enter password")
write("Password: ")
input = read()
if input == pass then
print("Correct password")
sleep(1)
print("Access granted")
sleep(2)
redstone.setOutput("right", true)
sleep(4)
redstone.setOutput("right", false)
else
print("Password Incorrect")
redstone.setOutput("left", true)
sleep(4)
redstone.setOutput("left", true)
end
Your problems were:
1- using
 write "Password: "
(bad way to call a function)
instead of
write("Password: ")
(good way to call a function)
2- using
pass = 1337
(stores 1337 as a number)
instead of
 pass = "1337"
(stores 1377 as test)
3-using
redstone.setOutout("right", false) 
(typo)
instead of
 redstone.setOutput("right", false)
(correct spelling of Output)
AwesomePwningGuy #8
Posted 04 November 2012 - 05:16 AM
Thanks I looked through and found the output error but the rest i didn't thanks. :D/>/> :)/>/> :)/>/> :)/>/> :)/>/> :)/>/>