Jump to content




WHAT AM I DOING WRONG?

help

5 replies to this topic

#1 Pilot1001

  • New Members
  • 1 posts

Posted 27 October 2016 - 07: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

#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 28 October 2016 - 12:31 AM

You can't "else" an "if" block you've already "end"ed.

#3 apemanzilla

  • Members
  • 1,421 posts

Posted 28 October 2016 - 02:14 AM

Also, there's a missing quote in the print statement.

#4 JustIan12

  • Members
  • 57 posts

Posted 28 October 2016 - 07: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 by JustIan122, 28 October 2016 - 07:27 AM.


#5 houseofkraft

  • Members
  • 170 posts
  • LocationUSA

Posted 29 October 2016 - 12: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


#6 Anavrins

  • Members
  • 775 posts

Posted 29 October 2016 - 03: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 by Anavrins, 29 October 2016 - 03:20 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users