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

A If Statement after a if statement.

Started by rudemario, 28 October 2012 - 08:29 PM
rudemario #1
Posted 28 October 2012 - 09:29 PM
So I've been working on a login system for my computer, because i'm going to port my world to a server for me and my friends to play on, and the computer was also going to control a door next to the computer that led to a storage room.
So I figured that after asking for the login password, it would then ask if you wanted to enter the door to the left, and if you said no, it would open up to the rest of the computer, and if you said yes, it would initiate a door opening sequence and then return to the main computer. I before had decided that after getting into the program, you could just run a program that entered the door, but then it wouldn't be hidden by using the asterisk string, input = read("*") so I tried making a if statement after a if statement, it looked a little like this:

print("Welcome, please enter you're password:")
input = read("*")
if input == "HelloWorld" then
print("Password accepted, access granted.")
sleep(1)
print("Welcome rudemario, if you need to open the door to the left, please enter the correct password now:")
else
print("Password Incorrect, Access Denied."
sleep(1)
print("Initiating System Shutdown…")
sleep(1)
textutils.slowPrint("Goodbye!")
os.shutdown()
end
input = read("*")
if input == "creeperface" then
print("Password Accepted, Please Proceed.")
redstone.setOutput("left", true)
sleep(3)
redstone.setOutput("left", false)
print("Door now closed, enter the override code now to re-open the door.")
else
print("Welcome, rudemario.")
end

I have also tried to make the if statement inside of the if statement, and logically thats how it would go, right?
so now i'm at a stalemate, confused and frustrated, I request you're friendly community's help :/
Lyqyd #2
Posted 28 October 2012 - 09:38 PM
You mean something like this:


print("Welcome, please enter your password:")
input = read("*")
if input == "HelloWorld" then
    print("Password accepted, access granted.")
    sleep(1)
    print("Welcome rudemario, if you need to open the door to the left, please enter the correct password now:")
    input = read("*")
    if input == "creeperface" then
        print("Password Accepted, Please Proceed.")
        redstone.setOutput("left", true)
        sleep(3)
        redstone.setOutput("left", false)
        print("Door now closed, enter the override code now to re-open the door.")
    else
        print("Welcome, rudemario.")
    end
else
    print("Password Incorrect, Access Denied.")
    sleep(1)
    print("Initiating System Shutdown...")
    sleep(1)
    textutils.slowPrint("Goodbye!")
    os.shutdown()
end
rudemario #3
Posted 28 October 2012 - 09:44 PM
You mean something like this:


print("Welcome, please enter your password:")
input = read("*")
if input == "HelloWorld" then
	print("Password accepted, access granted.")
	sleep(1)
	print("Welcome rudemario, if you need to open the door to the left, please enter the correct password now:")
	input = read("*")
	if input == "creeperface" then
		print("Password Accepted, Please Proceed.")
		redstone.setOutput("left", true)
		sleep(3)
		redstone.setOutput("left", false)
		print("Door now closed, enter the override code now to re-open the door.")
	else
		print("Welcome, rudemario.")
	end
else
	print("Password Incorrect, Access Denied.")
	sleep(1)
	print("Initiating System Shutdown...")
	sleep(1)
	textutils.slowPrint("Goodbye!")
	os.shutdown()
end

Yes, I tried that, and can't seem to remember the error, but all I knew was that it actually looked just about identical to your post.
Lyqyd #4
Posted 28 October 2012 - 10:01 PM
So, did you try that exact code I just posted?
XoX #5
Posted 28 October 2012 - 10:54 PM
You either have to give is the exact code or we can't look for errors.
The code you wrote already has a few syntax errors but I am guessing that it isn't the actual code.