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

Help with Door Program

Started by DeltaHotel, 24 December 2014 - 02:24 PM
DeltaHotel #1
Posted 24 December 2014 - 03:24 PM
Hi Guys
I am new to computer craft and am learning lua piece by piece but i am stuck at this point. I have attempted to troubleshoot using your helpful guide but can't find the problem so can anyone help me with this. I am trying to make a door program that allows me to enter a username and a password for a door set to the right. The error is = 'expected' line 16. Code Below. Also if you see any other problems please can you point them out before i struggle with more.

username = Daniel
password = 080397
print("Welcome to Nuclear Control")
write("Username: ")
user = read()
if user == username then
print("Username Accepted, Enter Password")
write("Password: ")
pass = read(*)
  if pass == password then
   print("Password Accepted, Welcome Daniel")
   rs.setOutput("Right", true)
   sleep(4)
   os.reboot
  else not pass == password then
   print("Password Denied, System Rebooting")
   sleep(2)
   os.reboot
  end
else user not = username then
print("Username Invailed, Restarting System")
sleep(2)
os.reboot
end
Cranium #2
Posted 24 December 2014 - 04:26 PM
You want to switch that else into an elseif, and you should be good. Else conditions don't take arguments like that.

if condition then
    doStuff()
elseif otherCondition then
    doOtherStuff()
else
    doAnythingElse()
end
Exerro #3
Posted 24 December 2014 - 05:01 PM
The error is referring to this line:
else user not = username then
It should be this:
elseif user ~= username then

Writing "not =" isn't possible in Lua, you have to use "~=" which effectively means the same thing, and as Cranium stated, you can't have arguments with an else condition, you must use elseif.

A couple more errors I just noticed:
else not pass == password then
similar to above, should be…
elseif pass ~= password then

And you forgot to put brackets (parentheses) after "os.reboot" in 3 cases (one being the second to last line).
Edited on 24 December 2014 - 04:22 PM
DeltaHotel #4
Posted 24 December 2014 - 05:18 PM
still comes up with that error even when changed to elseif statment
DeltaHotel #5
Posted 24 December 2014 - 05:40 PM

os.pullEvent = os.pullEventRaw
username = Daniel
password = 080397
print("Welcome to Nuclear Control")
write("Username: ")
user = read()
if user == username then
  print("Username Accepted, Enter Password")
  write("Password: ")
  pass = read(X)
   if pass == password then
    print("Password Accepted,Welcome Daniel")
    rs.setOutput("right", true)
    sleep(4)
    os.reboot
   elseif pass ~= password then
    print("Password Denied,System Rebooting")
    sleep(2)
    os.reboot
  end
elseif user ~= username then
  print("Username Invailed, Restarting System")
  sleep(2)
  os.reboot
end
Changed to this and it still dosent work
DeltaHotel #6
Posted 24 December 2014 - 05:41 PM
Works now CHEERS PEOPLE
DeltaHotel #7
Posted 24 December 2014 - 09:06 PM

os.pullEvent = os.pullEventRaw
username = "Admin"
password = "Creeper"
print("Welcome to Nuclear Control")
write("Username: ")
user = read()
if user == username then
  print("Username Accepted, Enter Password")
  write("Password: ")
  pass = read(X)
   if pass == password then
    print("Password Accepted, Welcome Daniel")
    rs.setOutput("right", true)
    sleep(4)
    os.reboot()
   else
    print("Password Denied, System Rebooting")
    sleep(2)
    os.reboot()
  end
elseif user ~= username then
  print("Username Invailed, Restarting System")
  sleep(2)
  os.reboot()
end
Here is my end product of coding Thanks for the help