695 posts
Location
In my basement.
Posted 23 February 2013 - 12:21 AM
Hi! I'm Trying to make a login program. But When i try to run it i get this error: bios:338: [string "startup"]:27 'end' expected (to close 'if' at line 13) how do i fix it? Heres My code:
local pullEvent = os.pullEvent
os.pullEvent = os.pullEventRaw
local scode = "1525"
local code = "8126"
local out = "back"
local time = 5
term.clear()
term.setCursorPos(1,1)
write("Please input code> ")
local input = read("*")
if input == code then
t
term.clear()
term.setCursorPos(1,1)
print("Correct code!")
rs.setOutput(out, true)
sleep(time)
rs.setOutput(out, false)
os.reboot()
else
term.clear()
term.setCursorPos(1,1)
print("Incorrect code!")
sleep(2)
os.reboot()
elseif input == scode then
os.pullEvent = pullEvent
print("You can terminate the program now")
end
8543 posts
Posted 23 February 2013 - 04:27 AM
Split into new topic.
Your elseif clause needs to be before your else clause.
537 posts
Location
Copenhagen, Denmark
Posted 23 February 2013 - 09:17 AM
Use pastebin or something damnit. Most people don't even bother reading your code if it's not formatted.
71 posts
Location
Latvia
Posted 23 February 2013 - 09:52 AM
Lyquid already told you what to do, but in case you don't understand here is the fixed code, just copy%paste it.
local pullEvent = os.pullEvent
os.pullEvent = os.pullEventRaw
-- [[ Variables ]] --
local scode = "1525"
local code = "8126"
local out = "back"
local time = 5
-- [[ Main Part ]] --
term.clear()
term.setCursorPos(1,1)
write("Please input code> ")
local input = read("*")
if input == code then
term.clear()
term.setCursorPos(1,1)
print("Correct code!")
rs.setOutput(out, true)
sleep(time)
rs.setOutput(out, false)
os.reboot()
elseif input == scode then
os.pullEvent = pullEvent
print("You can terminate the program now")
else
term.clear()
term.setCursorPos(1,1)
print("Incorrect code!")
sleep(2)
os.reboot()
end
And next time please format your code correctly, and use pastebin or code (<>) option in the editor.
758 posts
Location
Budapest, Hungary
Posted 23 February 2013 - 10:08 AM
Formatted and bugfixed version of the code:
Spoiler
local pullEvent = os.pullEvent
os.pullEvent = os.pullEventRaw
local scode = "1525"
local code = "8126"
local out = "back"
local time = 5
term.clear()
term.setCursorPos(1, 1)
write("Please input code> ")
local input = read("*")
if input == code then
-- t -- commented cuz WTF's that "t" here?!
term.clear()
term.setCursorPos(1, 1)
print("Correct code!")
rs.setOutput(out, true)
sleep(time)
rs.setOutput(out, false)
os.reboot()
elseif input == scode then
-- umm... - is this a backdoor or something like that?
os.pullEvent = pullEvent
print("You can terminate the program now") -- but there's nothing that waits for termination
-- os.pullEvent("an_event_that_never_fires") -- uncomment this line if you're sure about waiting for termination
-- while true do os.pullEvent() end -- this is prettier than the solution above but is harder to understand too
else -- else must be the last part of the IF block
term.clear()
term.setCursorPos(1, 1)
print("Incorrect code!")
sleep(2)
os.reboot()
end
Code that I prefer to use:
Spoiler
local debugMode = true -- set this to false to prevent terminating
local debugPassword = "1525"
local correctPassword = "8126"
local output = "back"
local signalLength = 5
local pullEvent = os.pullEvent
os.pullEvent = os.pullEventRaw
while true do
term.clear()
term.setCursorPos(1, 1)
write("Enter password: ")
local password = read("*")
if password == correctPassword then
rs.setOutput(output, true)
sleep(signalLength)
rs.setOutput(output, false)
elseif password == debugPassword and debugMode then
os.pullEvent = pullEvent
print("You can now terminate the program")
while true do os.pullEvent() end
else
print("Incorrect password! GET AWAY!")
sleep(2)
end
end
EDIT: Yay ninja'd
12 posts
Posted 24 February 2013 - 10:02 AM
Don't want to sound like an idiot. But shouldn't the 3rd to last line be
os.pullEvent = os.pullEventRaw
758 posts
Location
Budapest, Hungary
Posted 24 February 2013 - 11:31 AM
Don't want to sound like an idiot. But shouldn't the 3rd to last line be
os.pullEvent = os.pullEventRaw
Nope. With os.pullEvent = pullEvent, he restores the good old os.pullEvent, because it points to os.pullEventRaw before that.
pullEvent (not os.pullEvent but pullEvent) is declared on the 1st line, and it points to the old os.pullEvent.
695 posts
Location
In my basement.
Posted 25 February 2013 - 07:16 PM
Thanks for The help!