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

at elseif statement return to top of code

Started by nawm, 16 November 2012 - 05:19 PM
nawm #1
Posted 16 November 2012 - 06:19 PM
so I have a password script


os.pullEvent = os.pullEventRaw
term.clear()
term.setCursorPos(1,1)
password = "password"
debug = "debug"
alarm = "alarm"
write("Enter Password: ")
input = read()
term.clear()
term.setCursorPos(1,1)
if input == password then
    print("Password Correct!")
    rs.setOutput("left",true)
    sleep(5)
    rs.setOutput("left",false)
    os.shutdown()
elseif == debug then
    exit()
elseif input == slarm then
    rs.setOutput("right",flase)
    os.shutdown()
else
    print("Incorrect Password, sounding alarm!")
    sleep(2)
    rs.setOutput("right",true)
end

Im looking for away to rerun the script after the else statement
Shnupbups #2
Posted 16 November 2012 - 06:31 PM
Try putting the program in a while true do loop. Like this:

os.pullEvent = os.pullEventRaw
while true do
    term.clear()
    term.setCursorPos(1,1)
    password = "password"
    debug = "debug"
    alarm = "alarm"
    write("Enter Password: ")
    input = read()
    term.clear()
    term.setCursorPos(1,1)
    if input == password then
	    print("Password Correct!")
	    rs.setOutput("left",true)
	    sleep(5)
	    rs.setOutput("left",false)
	    os.shutdown()
    elseif == debug then
	    exit()
    elseif input == slarm then
	    rs.setOutput("right",flase)
	    os.shutdown()
    else
	    print("Incorrect Password, sounding alarm!")
	    sleep(2)
	    rs.setOutput("right",true)
    end
end
There. Done!
Luanub #3
Posted 16 November 2012 - 06:32 PM
Use a while loop

while true do
--insert code you want repeated
end
remiX #4
Posted 17 November 2012 - 01:35 AM
One of your elseif's is
elseif == debug then
should be
elseif input == debug then
MaHuJa #5
Posted 17 November 2012 - 01:43 AM
elseif input == slarm then

I don't think you meant that either.

+1 for Shnupbups100's answer, though I would usually place the assignments before the loop. Usually at the very top.
remiX #6
Posted 17 November 2012 - 04:38 AM
Yeah there is no point of changing the passwords for all of them all the time because they remain the same, and you made quite a few spelling mistakes.

os.pullEvent = os.pullEventRaw
password = "password"
debug = "debug"
alarm = "alarm"
while true do
    term.clear() term.setCursorPos(1,1)
    write("Enter Password: ")
    input = read()
    term.clear() term.setCursorPos(1,1)
    if input == password then
        print("Password Correct!")
        rs.setOutput("left",true)
        sleep(5)
        rs.setOutput("left",false)
        os.shutdown()
    elseif input == debug then
        exit()
    elseif input == alarm then   -- 'alarm' spelt wrong.
        rs.setOutput("right",false)  -- you also spelt false incorrectly here
        os.shutdown()
    else
        print("Incorrect Password, sounding alarm!")
        sleep(2)
        rs.setOutput("right",true)
    end
end