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

bios:338: [string "startup"]:27 'end' expected

Started by Mackan90096, 22 February 2013 - 11:21 PM
Mackan90096 #1
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
Lyqyd #2
Posted 23 February 2013 - 04:27 AM
Split into new topic.

Your elseif clause needs to be before your else clause.
Mads #3
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.
exploder #4
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.
LBPHacker #5
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
Lewis.holcombe #6
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
LBPHacker #7
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.
Mackan90096 #8
Posted 25 February 2013 - 07:16 PM
Thanks for The help!