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

'end' expected (to close 'if' at line 12)

Started by CrazyCoke, 26 October 2012 - 01:50 PM
CrazyCoke #1
Posted 26 October 2012 - 03:50 PM
Hello guys can someone help me ??
I have a program voor my Reactor to open de locked door, but I gain every time this error:
'end' expected (to close 'if' at line 12)

PROGRAM:

term.clear()
term.setCursorPos(5, 5)
print("##############################################")
print("# #")
print("# Hello Mr/Mrs, #")
print("# Type in your ID please: #")
print("# #")
print("# #")
print("##############################################")
write("")
ID = io.read()
if ID == "Mr. Reactor" then
term.clear()
term.setCursorPos(5, 5)
print("##############################################")
print("# #")
print("# Type now your password in please: #")
print("# #")
print("# #")
print("# #")
print("##############################################")
write("")
password = io.read()
if password == "1997" then
term.clear()
term.setCursorPos(5, 4)
print("##############################################")
print("# #")
print("# #")
print("# Welcome and be careful! #")
print("# #")
print("# #")
print("##############################################")
rs.setOutput("left", true)
sleep(3)
rs.setOutput("left", false)
os.shutdown()
end
else
term.clear()
term.setCursorPos(5, 5)
print("##############################################")
print("# #")
print("# Sorry, wrong input, #")
print("# Please try again! #")
print("# #")
print("# #")
print("# #")
print("##############################################")
write("")
ID = io.read()
if ID == "Mr. Reactor" then
term.clear()
term.setCursorPos(5, 5)
print("##############################################")
print("# #")
print("# Type now your password in please: #")
print("# #")
print("# #")
print("# #")
print("##############################################")
write("")
password = io.read()
if password == "1997" then
term.clear()
term.setCursorPos(5, 5)
print("##############################################")
print("# #")
print("# #")
print("# Welcome and be careful! #")
print("# #")
print("# #")
print("##############################################")
rs.setOutput("left", true)
sleep(3)
rs.setOutput("left", false)
os.shutdown()
end
else
term.clear()
term.setCursorPos(5, 5)
print("##############################################")
print("# #")
print("# Sorry, I need to #")
print("# shutdown! #")
print("# #")
print("# #")
print("##############################################")
sleep(1)
os.shutdown()
end
else
term.clear()
term.setCursorPos(5, 5)
print("##############################################")
print("# #")
print("# Sorry, wrong input, #")
print("# Please try again! #")
print("# #")
print("# #")
print("# #")
print("##############################################")
write("")
password = io.read()
if password == "1997" then
term.clear()
term.setCursorPos(5, 5)
print("##############################################")
print("# #")
print("# #")
print("# Welcome and be careful! #")
print("# #")
print("# #")
print("##############################################")
rs.setOutput("left", true)
sleep(3)
rs.setOutput("left", false)
os.shutdown()
end
else
term.clear()
term.setCursorPos(5, 5)
print("##############################################")
print("# #")
print("# Sorry, I need to #")
print("# shutdown! #")
print("# #")
print("# #")
print("##############################################")
sleep(1)
os.shutdown()
end
end

Please respond as soon as possible
do not look on the failed SHIFT + 3
CrazyCoke #2
Posted 26 October 2012 - 03:52 PM
oooh and that 'end' expected is on line 92
anonimo182 #3
Posted 26 October 2012 - 03:53 PM
You could use a loop instead of repeating the code 4 times
CrazyCoke #4
Posted 26 October 2012 - 03:58 PM
I am not so pro in Computercraft and what you are saying with WindOS
xD
Ditto8353 #5
Posted 26 October 2012 - 03:58 PM
Just a couple tips for the future.
Use code tags to make your code easier for people to read.
 
If you post questions like this in the "Ask a Pro" board, there are usually a ton of programmers just waiting to help.
Orwell #6
Posted 26 October 2012 - 04:03 PM
I am not so pro in Computercraft and what you are saying with WindOS
xD

And… The code about WindOS is in his signature. It's not related to his answer. :D/>/>
anonimo182 #7
Posted 26 October 2012 - 04:03 PM
use this code:


term.clear()
term.setCursorPos(5, 5)
while true do
print("##############################################")
print("# #")
print("# Hello Mr/Mrs, #")
print("# Type in your ID please: #")
print("# #")
print("# #")
print("##############################################")
write("")
ID = io.read()
if ID == "Mr. Reactor" then
term.clear()
term.setCursorPos(5, 5)
print("##############################################")
print("# #")
print("# Type now your password in please: #")
print("# #")
print("# #")
print("# #")
print("##############################################")
write("")
password = io.read()
if password == "1997" then
term.clear()
term.setCursorPos(5, 4)
print("##############################################")
print("# #")
print("# #")
print("# Welcome and be careful! #")
print("# #")
print("# #")
print("##############################################")
rs.setOutput("left", true)
sleep(3)
rs.setOutput("left", false)
end
else
term.clear()
term.setCursorPos(5, 5)
print("##############################################")
print("# #")
print("# Sorry, wrong input, #")
print("# Please try again! #")
print("# #")
print("# #")
print("# #")
print("##############################################")
end
end
end
CrazyCoke #8
Posted 26 October 2012 - 04:15 PM
Why:

font=helvetica, arial, sans-serif] by print…..

?????
anonimo182 #9
Posted 26 October 2012 - 04:21 PM
my error, already fixed
CrazyCoke #10
Posted 26 October 2012 - 04:40 PM
Ok

I am trying using loops but i need to see a tutorial first.
I don't know how it works xD
anonimo182 #11
Posted 26 October 2012 - 04:42 PM
the loops are easy, use the loop and when you said end, it will repeat, accordingly to the loop, and you can break it or finish it, according to the loop
Heracles421 #12
Posted 26 October 2012 - 05:04 PM
Well, a loop is simple to use. You just set conditions for your loops, in this case you need to make a loop when you input a wrong password, something like:

function password()
if pass == "Password" then
    print("Welcome USER")
    rs.setOutput("side", true)
    sleep(3)
    rs.setOutput("side", false)
    password()
else 
    print("Wrong Password!")
    sleep(3)
    password()
end
end

Here you're telling the computer: If the password is correct, open the door. If it is not correct say Wrong Password and ask for the password again
Mandrake Fernflower #13
Posted 08 November 2012 - 03:55 PM
What the hell is this I dont even… Can we get this thread locked?

EDIT: what I said was stupid
digpoe #14
Posted 09 November 2012 - 07:12 AM
io.read() I belive does not read from the input that you type in.. Someone correct me if I'm wrong though.

A better way would be to do is input=read(FORMATSTYLE)
PixelToast #15
Posted 09 November 2012 - 07:14 AM
io.read() I belive does not read from the input that you type in.. Someone correct me if I'm wrong though.

A better way would be to do is input=read(FORMATSTYLE)
io.read works but not as well as the normal read
digpoe #16
Posted 09 November 2012 - 07:16 AM
io.read() I belive does not read from the input that you type in.. Someone correct me if I'm wrong though.

A better way would be to do is input=read(FORMATSTYLE)
io.read works but not as well as the normal read
Oh. I did not know that. I just use Ctrl+T protection and use read() - Well, I suppose io.read() still needs Ctrl+T protection.