Jump to content




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



  • You cannot reply to this topic
15 replies to this topic

#1 CrazyCoke

  • Members
  • 11 posts

Posted 26 October 2012 - 02: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

#2 CrazyCoke

  • Members
  • 11 posts

Posted 26 October 2012 - 02:52 PM

oooh and that 'end' expected is on line 92

#3 anonimo182

  • Members
  • 252 posts
  • LocationIn the universe

Posted 26 October 2012 - 02:53 PM

You could use a loop instead of repeating the code 4 times

#4 CrazyCoke

  • Members
  • 11 posts

Posted 26 October 2012 - 02:58 PM

I am not so pro in Computercraft and what you are saying with WindOS
xD

#5 Ditto8353

  • New Members
  • 138 posts

Posted 26 October 2012 - 02:58 PM

Just a couple tips for the future.
Use code tags to make your code easier for people to read. [ code] [ /code]
If you post questions like this in the "Ask a Pro" board, there are usually a ton of programmers just waiting to help.

#6 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

Posted 26 October 2012 - 03:03 PM

View PostCrazyCoke, on 26 October 2012 - 02:58 PM, said:

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/>

#7 anonimo182

  • Members
  • 252 posts
  • LocationIn the universe

Posted 26 October 2012 - 03: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


#8 CrazyCoke

  • Members
  • 11 posts

Posted 26 October 2012 - 03:15 PM

Why:

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

?????

#9 anonimo182

  • Members
  • 252 posts
  • LocationIn the universe

Posted 26 October 2012 - 03:21 PM

my error, already fixed

#10 CrazyCoke

  • Members
  • 11 posts

Posted 26 October 2012 - 03:40 PM

Ok

I am trying using loops but i need to see a tutorial first.
I don't know how it works xD

#11 anonimo182

  • Members
  • 252 posts
  • LocationIn the universe

Posted 26 October 2012 - 03: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

#12 Heracles421

  • Members
  • 258 posts

Posted 26 October 2012 - 04: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

#13 Mandrake Fernflower

  • Members
  • 117 posts
  • LocationDark Side of The Moon

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

#14 digpoe

  • Members
  • 92 posts

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)

#15 PixelToast

  • Signature Abuser
  • 2,265 posts
  • Location3232235883

Posted 09 November 2012 - 07:14 AM

View Postdigpoe, on 09 November 2012 - 07:12 AM, said:

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

#16 digpoe

  • Members
  • 92 posts

Posted 09 November 2012 - 07:16 AM

View PostPixelToast, on 09 November 2012 - 07:14 AM, said:

View Postdigpoe, on 09 November 2012 - 07:12 AM, said:

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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users