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

Double pass door problems

Started by dunkee, 17 December 2012 - 12:38 AM
dunkee #1
Posted 17 December 2012 - 01:38 AM
So, i saw a program on here that lets you have 2 passwords, so i tried to make my own so that if you fail the first time you get to put in another password. i tried this code:
while true do
print ("Enter pass:")
read("*")
if answer == "loopycoopy" then
print ("Please enter")
rs.setOutput("left", true)
sleep(3)
rs.setOutput("left", true)
os.reboot()
else
print ("Enter Pass Two")
print ("Enter Pass:")
read ("*")
if answer == "Admin" then
print ("Please enter")
rs.setOutput("right", true)
sleep(3)
rs.setOutput("right", true)
os.reboot()
else
print ("You may NOT enter")
sleep(1)
os.reboot()
When i use this code it says there is an = needed at one of the else's and i don't know why. I want to use this in a pack of programs i'm planning to put here. Anyway, could someone help me fix this code? i took out the second password and it worked fine, so it must be either that or the fact that something won't allow two else's. I have no idea at all. I also tried to put an end at the end (go figure) but now it wants me to put an = there too.

(And yes, i picked loopycoopy as my password :P/>)

EDIT: I think it is solved, here is my code now:

while true do
print ("Enter pass:")
answer = read("*")
if answer == "loopycoopy" then
print ("Please enter")
rs.setOutput("left", true)
sleep(3)
rs.setOutput("left", true)
os.reboot()
else
print ("Enter Pass Two")
print ("Enter Pass:")
answer = read ("*")
if answer == "Admin" then
print ("Please enter")
rs.setOutput("right", true)
sleep(3)
rs.setOutput("right", true)
os.reboot()
else
print ("You may NOT enter")
sleep(1)
os.reboot()
end
end
end
end
end
I think that it is fixed now, thanks to;
TheOriginalBIT

for helping me.
theoriginalbit #2
Posted 17 December 2012 - 02:03 AM
your missing a large amount of "end"'s for the while loop and the if statements. also you should have
answer = read("*")
dunkee #3
Posted 17 December 2012 - 03:41 AM
your missing a large amount of "end"'s for the while loop and the if statements. also you should have
answer = read("*")
Could you further explain how many "end"s i need? I'm new to lua and i need quite a bit of help. Also, would any part of this need an extra space at the start of the line?
Eg:
while true do
print ("NEW LINE :D/>/>")
  end
end
Thanks for the help. I think i'm starting to understand how it works. -_-/>

EDIT: Do you mean that all of the "read = ("*")"s should be "answer = read("*")"s?
theoriginalbit #4
Posted 17 December 2012 - 04:06 AM
your missing a large amount of "end"'s for the while loop and the if statements. also you should have
answer = read("*")
Could you further explain how many "end"s i need? I'm new to lua and i need quite a bit of help. Also, would any part of this need an extra space at the start of the line?
Eg:
while true do
print ("NEW LINE :D/>/>/>")
  end
end

you need and end to match and close off each of the following: if, while, for, repeat, and functions.

whitespace doesn't change anything about how the program runs, however it does make it easier to read and see when you have missed things like ends

EDIT: Do you mean that all of the "read = ("*")"s should be "answer = read("*")"s?

yes. what is happenning there is read("*") gets the input from the user, which is shown to them with "*"'s and stores it in the variable answer (or what ever you wish to call the variable). This variable is then what you use throughout the rest of the program, whether thats via printing it, comparing it to something or whatever.
dunkee #5
Posted 17 December 2012 - 07:51 AM
your missing a large amount of "end"'s for the while loop and the if statements. also you should have
answer = read("*")
Could you further explain how many "end"s i need? I'm new to lua and i need quite a bit of help. Also, would any part of this need an extra space at the start of the line?
Eg:
while true do
print ("NEW LINE :D/>/>/>/>")
  end
end

you need and end to match and close off each of the following: if, while, for, repeat, and functions.

whitespace doesn't change anything about how the program runs, however it does make it easier to read and see when you have missed things like ends

EDIT: Do you mean that all of the "read = ("*")"s should be "answer = read("*")"s?

yes. what is happenning there is read("*") gets the input from the user, which is shown to them with "*"'s and stores it in the variable answer (or what ever you wish to call the variable). This variable is then what you use throughout the rest of the program, whether thats via printing it, comparing it to something or whatever.
I think i fixed the code, could you check the post and tell me? If this is solved i can mark this post [Solved] PLUS if i do get to making that program pack (or just plain releasing this one) i shall give credit for the help. Thanks for the help, i'm gonna be so pumped if i can get this working :D/> !
*Plays Still Alive*
SpoilerThis was a triumph.
I'm making a note here: HUGE SUCCESS.
It's hard to overstate my satisfaction.
ComputerCraft Forums
We do what we must
because we can.
For the good of all of us.
Except the ones who are dead.
But there's no sense crying over every mistake.
You just keep on trying till you run out of cake.
*Eats cake whole*
I ran out of cake…
*glaDOS explodes*
HOLY SH…
*Head Explodes*
dunkee #6
Posted 17 December 2012 - 09:51 AM
Nope, it got broken and i had to full lockdown on the wonderful post i made *sniff* Please could you fix it for me? I need your help! PLEASE! *sniff* *drip*
Check it here: http://www.computercraft.info/forums2/index.php?/topic/7152-simple-double-pass-door-lock-experimental-v01/page__fromsearch__1
I spent *sniff* AN HOUR on that post *drip* then i tested the code and it broke! Then i spent 15 MINS editing the page to block off links *sniff, drip* and to warn people not to use the code as it is *sniff* BROKEN! *Crys out loud*
remiX #7
Posted 17 December 2012 - 09:58 AM
What exactly is the problem? Looks like to me that you have too many ends. This one should work

os.pullEvent = os.pullEventRaw()
while true do
    term.clear()
    term.setCursorPos(1,1)
    print ("Enter pass:")
    pass1 = read("*")
    if pass1 == "loopycoopy" then
        print("Please enter")
        rs.setOutput("left", true)
        sleep(3)
        rs.setOutput("left", true)
        os.reboot()
    else
        print("Incorrect password!\nEnter Pass Two")
        write("Enter Pass:")
        pass2 = read("*")
        if pass2 == "Admin" then
            print ("Please enter")
            rs.setOutput("right", true)
            sleep(3)
            rs.setOutput("right", true)
            os.reboot()
        else
            print ("You may NOT enter")
            sleep(1)
            os.reboot()
        end
    end
end

PS: Please do not spam your threads