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

WHAT AM I DOING WRONG?

Started by Pilot1001, 27 October 2016 - 06:42 PM
Pilot1001 #1
Posted 27 October 2016 - 08:42 PM
So i made a simple door lock system but it seems not to be working? it gives me the
[string ".temp"]:13 '<eof>' expected error.

Take a look at this:

local x = "125690"

print(Enter password: ")

pass = read()

if pass == x then
print("Correct password!")
rs.setOutput("right", true)
sleep(4)
os.shutdown()
end
else
write("Incorrect password!")
sleep(2)
os.shutdown()
end
Bomb Bloke #2
Posted 28 October 2016 - 01:31 AM
You can't "else" an "if" block you've already "end"ed.
apemanzilla #3
Posted 28 October 2016 - 03:14 AM
Also, there's a missing quote in the print statement.
JustIan12 #4
Posted 28 October 2016 - 08:26 AM
You made the same mistakes I did lol :/

print("Door Lock")
write("Password: ")
password = read("*")

if password == "password123" then
print("Welcome Back")
sleep(1)
redstone.setOutput("right", true)
sleep(3)
os.shutdown()

else
print("Access Denied")
sleep(1)
term.clear()
print("Rebooting")
os.shutdown()
end

I wrote this a long time ago feel free to use this if you want :P/>
Edited on 28 October 2016 - 06:27 AM
houseofkraft #5
Posted 29 October 2016 - 01:19 AM
Here is the correct code:

local x = "125690"
print(Enter password: ")
pass = read()
if pass == x then
print("Correct password!")
rs.setOutput("right", true)
sleep(4)
os.shutdown()
else
write("Incorrect password!")
sleep(2)
os.shutdown()
end
Anavrins #6
Posted 29 October 2016 - 04:19 AM
Here is the correct code, you should look up how to use while loops, instead of doing shutdown.

local x = "125690"
while true do
  term.clear()
  term.setCursorPos(1,1)
  term.write("Enter password: ")
  local pass = read("*")
  if pass == x then
	print("Correct")
	rs.setOutput("right", true)
	sleep(4)
	rs.setOutput("right", false)
  else
	print("Incorrect")
	sleep(1)
  end
end
Edited on 29 October 2016 - 02:20 AM