11 posts
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
11 posts
Posted 26 October 2012 - 03:52 PM
oooh and that 'end' expected is on line 92
249 posts
Location
In the universe
Posted 26 October 2012 - 03:53 PM
You could use a loop instead of repeating the code 4 times
11 posts
Posted 26 October 2012 - 03:58 PM
I am not so pro in Computercraft and what you are saying with WindOS
xD
136 posts
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.
1054 posts
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/>/>
249 posts
Location
In the universe
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
11 posts
Posted 26 October 2012 - 04:15 PM
Why:
font=helvetica, arial, sans-serif] by print…..
?????
249 posts
Location
In the universe
Posted 26 October 2012 - 04:21 PM
my error, already fixed
11 posts
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
249 posts
Location
In the universe
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
248 posts
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
96 posts
Location
Dark 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
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)
2217 posts
Location
3232235883
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
92 posts
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.