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

Computer lock not working [COMPUTER CRAFT]

Started by Kron, 19 April 2013 - 09:24 AM
Kron #1
Posted 19 April 2013 - 11:24 AM
Hey guys, I'm creating housing for R-Loyalists in Minecraft. I am creating a door computer, however, it keeps giving me the error "bios:337: [string "startup"]:15: <eof> expected. Here's what I have so far.

term.clear()
term.setCursorPos(1,1)
print("What is your rank, USER?")
print(" ")
term.setTextColor(colors.green)
print("Citizen | CWU | MetroPolice |")
print("Security | Admin | Mechanic |")
term.setTextColor(colors.white)
write(">> ")
if input == "Citizen" then
 print("You do not have access!")
 os.reboot()
 end
elseif input == "CWU" then
 print("Welcome!")
 end
elseif input == "MetroPolice" then
 print("Welcome!")
 end
elseif input == "Admin" then
 print("Welcome, Administraitor Crontic!")
 end
elseif input == "Mechanic" then
 print("Welcome. Your screen usage is being recorded.")
 end
else
 print("Pardon? I dont understand.")
 os.reboot()
 end
Engineer #2
Posted 19 April 2013 - 11:28 AM
You have quite a lot ends too much.
This is what a if statement should look like:

if something then 
   --do stuff
elseif somethingElse then
   --do stuff
end

So you close the statement once, not multiple times. Just remove the ends in your code and keep the last one :)/>
TheOddByte #3
Posted 19 April 2013 - 11:36 AM
Do as Engineer said and remove every end except the last one
since when it's elseif it still counts as one end you need for the if statement and not a new one.
Kron #4
Posted 19 April 2013 - 11:51 AM
The program runs, but with the 'else', it gives me that message and doesn't let me type.
Sammich Lord #5
Posted 19 April 2013 - 11:57 AM
Fixed code.

term.clear()
term.setCursorPos(1,1)
print("What is your rank, USER?")
print(" ")
term.setTextColor(colors.green)
print("Citizen | CWU | MetroPolice |")
print("Security | Admin | Mechanic |")
term.setTextColor(colors.white)
write(">> ")
local input = read()
if input == "Citizen" then
print("You do not have access!")
os.reboot()
elseif input == "CWU" then
print("Welcome!")
elseif input == "MetroPolice" then
print("Welcome!")
elseif input == "Admin" then
print("Welcome, Administraitor Crontic!")
elseif input == "Mechanic" then
print("Welcome. Your screen usage is being recorded.")
else
print("Pardon? I dont understand.")
os.reboot()
end
You also forgot to define the input var.
Izodn #6
Posted 19 April 2013 - 12:18 PM
Fixed code.

term.clear()
term.setCursorPos(1,1)
print("What is your rank, USER?")
print(" ")
term.setTextColor(colors.green)
print("Citizen | CWU | MetroPolice |")
print("Security | Admin | Mechanic |")
term.setTextColor(colors.white)
write(">> ")
local input = read()
if input == "Citizen" then
print("You do not have access!")
os.reboot()
elseif input == "CWU" then
print("Welcome!")
elseif input == "MetroPolice" then
print("Welcome!")
elseif input == "Admin" then
print("Welcome, Administraitor Crontic!")
elseif input == "Mechanic" then
print("Welcome. Your screen usage is being recorded.")
else
print("Pardon? I dont understand.")
os.reboot()
end
You also forgot to define the input var.
I noticed that the "Pardon? I dont understand." will appear as if it's not showing since the os.reboot() is called right after.
Here's a fix so you don't need to os.reboot()
Spoiler

auth = "no"
while auth == "no" do
	auth = ""
	term.clear()
	term.setCursorPos(1,1)
	print("What is your rank, USER?")
	print(" ")
	term.setTextColor(colors.green)
	print("Citizen | CWU | MetroPolice |")
	print("Security | Admin | Mechanic |")
	term.setTextColor(colors.white)
	write(">> ")
	local input = read()
	if input == "Citizen" then
		print("You do not have access!")
		sleep(2)
	elseif input == "CWU" then
		print("Welcome!")
	elseif input == "MetroPolice" then
		print("Welcome!")
	elseif input == "Admin" then
		print("Welcome, Administraitor Crontic!")
	elseif input == "Mechanic" then
		print("Welcome. Your screen usage is being recorded.")
	else
		print("Pardon? I dont understand.")
		sleep(2)
		auth = "no"
	end
end

Edited: Forgot to put in sleep() &amp; remove os.reboot()