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

Password door lock help

Started by MrNewVegaz, 23 October 2012 - 01:11 AM
MrNewVegaz #1
Posted 23 October 2012 - 03:11 AM
Can someone please help me find the error in my coding?
I get this error when I try to run my program:

CraftOS 1.3
> doorlock
bios:206: [string "doorlock"]:25: 'end' expected
(to close 'while' at line 2)

————————————————————————–

Here is my coding:

os.pullEvent = os.pullEventRaw
while true do
term.clear()
term.setCursorPos(1, 1)
print("Door Terminal//Please Enter Password:")
input = read("*")
if input == "pass" then
print("Access Granted! Unlocking Door…")
redstone.setOutput("back", true)
sleep(8)
print("Locking Door…")
sleep(2)
redstone.setOutput("back", false)
end
if input == "pass:terminate" then
print("Program Terminated by Admin")
sleep(0.5)
print("To lock the door, run 'doorlock'")
redstone.setOutput("back", true)
os.pullEvent(terminate)
sleep(5)
end
else
print("Incorrect Password!")
sleep(2)
end
end
Shnupbups #2
Posted 23 October 2012 - 03:16 AM

bios:206: [string "doorlock"]:25: 'end' expected -- that means in the code of doorlock, on line 25, it expected to see another end
(to close 'while' at line 2) -- that other end will end of the while on line 2
Basically, you need another end at the end (pun unintended) of your code.
remiX #3
Posted 23 October 2012 - 03:56 PM
Instead of making a whole new if statement for a different input of password, use elseif


os.pullEvent = os.pullEventRaw
while true do
	term.clear()
	term.setCursorPos(1, 1)
	print("Door Terminal//Please Enter Password:")
	input = read("*")
	if input == "pass" then
		print("Access Granted! Unlocking Door...")
		redstone.setOutput("back", true)
		sleep(8)
		print("Locking Door...")
		sleep(2)
		redstone.setOutput("back", false)
	elseif input == "pass:terminate" then
		print("Program Terminated by Admin")
		sleep(0.5)
		print("To lock the door, run 'doorlock'")
		redstone.setOutput("back", true)
		sleep(5)
		os.pullEvent(terminate)
	else
		print("Incorrect Password!")
		sleep(2)
	end
end