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

Door locking system and coding HELP please

Started by SovietRussianSpy, 18 July 2014 - 03:16 AM
SovietRussianSpy #1
Posted 18 July 2014 - 05:16 AM
Ok here's my problem… In my base i wanted to set up like restrictions on the doors. The owner(me) when i type in the user name and password it opens all doors. The admin(a server member) when he types in his code it only opens certain doors and so on with the guest.

"This is how the code looks to the "t". I tried spacing it out but it wont post right and tbh i dont know how it should be spaced…This is the error i was getting: bios:366: [starting "startup" : 57: 'end' expected (to close 'if' at line 17)

local admin = "Cabalee"
local adminpass = "music"
local guest = "Footykaiser11"
local guestpass = "bigfoot"

while true do rs.setOutput("left", false)
rs.setOutput("right", false)
rs.setOutput("back", false)
term.clear()
term.setCursorPos(1,1)
write("Please enter your username: ")
local name = read()
if name == owner then
term.clear()
term.setCursorPos(1,1)
write("Please enter password: ")
local pass = read("*")
if pass == ownerpass then
rs.setOutput("left", true)
rs.setOutput("right", true)
rs.setOutput("back", true)
term.clear()
term.setCursorPos(1,1)
print("Access Granted. All rights have been invoked. Welcome back Soviet!")
sleep(10)

elseif name == admin then
term.clear()
term.setCursorPos(1,1)
write("Please enter password: ")
local pass = read("*")
if pass == adminpass then
rs.setOutput("left",true)
rs.serOutput("right", ture)
term.clear()
term.setCursorPos(1,1)
print("Access Granted. Access level medium. Welcome back Cabalee!")
sleep(10)

elseif name == guest then
term.clear()
term.setCursorPos(1,1)
write("Please enter password: ")
local pass = read("*")
if pass == guestpass then
rs.setOutput("left",true)
term.clear()
term.setCursorPos(1,1)
print("Access Granted. Low level access. Welcome back Footykiser!")
sleep(10)
end
end
Arektor #2
Posted 18 July 2014 - 07:16 AM
johnnic already said it, you've forgot 3 "end" at the end (:o/>)

But your program isn't working like you want it, it will always asking you your username.
I've rewrited it for you, with spaces and comments:

--Define users and their passwords--
local admin = "Cabalee"
local adminpass = "music"
local guest = "Footykaiser11"
local guestpass = "bigfoot"
--Start the loop--
while true do --If anything cannot happend, it will close the loop.
rs.setOutput("left", false)
rs.setOutput("right", false)
rs.setOutput("back", false)
term.clear()
term.setCursorPos(1,1)
write("Please enter your username: ")
local name = read() --Ask the username--
--If this is the owner's username--
if name == owner then
  term.clear()
  term.setCursorPos(1,1)
  write("Please enter password: ")
  local pass = read("*")
  if pass == ownerpass then
   rs.setOutput("left", true)
   rs.setOutput("right", true)
   rs.setOutput("back", true)
   term.clear()
   term.setCursorPos(1,1)
   print("Access Granted. All rights have been invoked. Welcome back Soviet!")
   sleep(10)
  end
--If this is the admin's one--
elseif name == admin then
  term.clear()
  term.setCursorPos(1,1)
  write("Please enter password: ")
  local pass = read("*")
  if pass == adminpass then
   rs.setOutput("left",true)
   rs.setOutput("right", true)
   term.clear()
   term.setCursorPos(1,1)
   print("Access Granted. Access level medium. Welcome back Cabalee!")
   sleep(10)
  end
--If this is the guest's one--
elseif name == guest then
  term.clear()
  term.setCursorPos(1,1)
  write("Please enter password: ")
  local pass = read("*")
  if pass == guestpass then
   rs.setOutput("left",true)
   term.clear()
   term.setCursorPos(1,1)
   print("Access Granted. Low level access. Welcome back Footykiser!")
   sleep(10)
  end
end
end

If you want you can remove the spaces and comments, it's just for the lisibility of the thing.
SovietRussianSpy #3
Posted 18 July 2014 - 05:10 PM
What about the local owner at the top? Im guessing it can just be added…

Also I just did the local owner to see if I could get it to work and it did, but it never did what it was suppose to do… It just kept asking me the same thing. It never said "Access Granted" or allow me to open the doors…
Edited on 18 July 2014 - 03:37 PM
Arektor #4
Posted 18 July 2014 - 06:22 PM
I'm sorry for the owner, but you haven't put it in the initial code ^^
To add it, you just have do that:

--Define users and their passwords--
local owner = "Ownername"
local ownerpass = "Ownerpass"
local admin = "Cabalee"
local adminpass = "music"
local guest = "Footykaiser11"
local guestpass = "bigfoot"

Have you tried with the others ? (guest and admin) ?
Are you sure you have take my code ? (Maybe you've forgot to save ._.)
SovietRussianSpy #5
Posted 18 July 2014 - 06:37 PM
It did work after all! I made a local owner but didn't make a local ownerpass :rolleyes:/> lol thanks!
Arektor #6
Posted 18 July 2014 - 09:34 PM
Happy to see I've helped you :)/> Good luck