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

Computercraft Door System

Started by hbomb79, 08 May 2014 - 07:57 PM
hbomb79 #1
Posted 08 May 2014 - 09:57 PM
I am trying to make a program that asks for a password to open a very large door I've created in the mindcrack crackpack, but…, I also want it to open the door if I press the button in the back of it, so that way I can open the door from the inside without the password, when the password or button is pressed I need the computer to emit a redstone signal for about ten seconds, it would be great if this could be changed, if any of you smart guys out there have a program that does this, please submit it so I could use it too, at least I'll learn :)/>
KingofGamesYami #2
Posted 08 May 2014 - 10:28 PM

function Password()
 os.pullEvent = os.pullEventRaw
 while true do
  local pass = read("*")
  if pass == "yourpasswordhere" then
   return true
  end
 end
end

function waitForRedstone()
 while true do
  os.pullEvent("redstone")
  if rs.getInput("side") then
   return
  end
 end
end

while true do
 parallel.waitForAny(waitForRedstone(), Password())
 rs.setOutput("side", true)
 sleep(1)
 rs.setOutput("side", false)
end
Edited code, should work now
Edited on 10 May 2014 - 12:27 AM
CometWolf #3
Posted 08 May 2014 - 11:00 PM
Note that king's usage of the parallel api is wrong and would error. You can't pass function calls to it, only function pointers. But aside from that, his code should do the trick.
hbomb79 #4
Posted 08 May 2014 - 11:08 PM
I noticed you edited your post king,is it fixed of the error comet pointed out?

After entering this code neither the button being pressed or entering the password worked, and if i tried typing it wouldnt work until I pressed the button on the back…. can you please fix this, i really cant figure it out
CometWolf #5
Posted 09 May 2014 - 05:23 AM
That edit was made prior to my post, so no :P/>
viluon #6
Posted 09 May 2014 - 08:16 AM

function Password()
os.pullEvent = os.pullEventRaw
while true do
  local pass = read("*")
  if pass == "yourpasswordhere" then
   return true
  end
end
end

local function catchEvent()
  e={os.pullEventRaw("redstone")}
end

while true do
parallel.waitForAny(catchEvent(), Password())
if e and e[1]=="redstone" then
--#open the door
end
end
something along the lines of this should work, note that you will still have to tell the code to open the door(toggle the redstone output)

(edited the code)

According to what CometWolf said, this code could do it (I haven't tested)
Edited on 09 May 2014 - 06:17 AM
hbomb79 #7
Posted 09 May 2014 - 08:22 AM
Ok, thanks, ill try it now and let you know

This code did not work, same issue as before, cant enter anything until the button has been pressed, and pressing it doesnt emit a signal and neither does the right pass… Remember, i want the button to be a bypass not a requirement, so i can press the button to leave or type the pass to enter, both must make the PC emit RS signal
CometWolf #8
Posted 09 May 2014 - 10:53 AM
the whole if e part isn't needed. Infact it makes the password not work. Personally i'd just use an anonymous function. Also, you should probably check where the redstone signal comes from.

while true do
  parallel.waitForAny(
    function()
      while true do
        os.pullEventRaw"redstone"
        if rs.getInput"back" then
          return
        end
      end
    end,
    password()
  )
  --open door
end
I was putting off doing this myself, cause im on my phone :P/>/>
Edited on 09 May 2014 - 08:55 AM
hbomb79 #9
Posted 12 May 2014 - 04:04 AM
This code still doesn't work, I still can't type in the PC till the button on the back has been pressed, also, idk how to add an interface so it at least says, please enter password… Even if the button is pressed or password is entered correctly it won't emit a signal.
CometWolf #10
Posted 12 May 2014 - 05:36 AM
Whops, my bad. Remove the brackets after password.
hbomb79 #11
Posted 12 May 2014 - 10:12 PM
Thanks, I can't test now but will soon, is the comma after the second to last end supposed to be there or is that a typo… Also, where would I enter a "Please Enter Password: "
CometWolf #12
Posted 12 May 2014 - 11:04 PM
It's supposed to be there yes, it's how you seperate function arguments eg. print("test","derp"). The input password part would be the password function defined in the other posts.
hbomb79 #13
Posted 12 May 2014 - 11:33 PM
So what you've posted isn't an addon for other posts right? I just copy that in the PC and remove the brackets after password, because I can't see a password check in there, it looks like it isn't complete?


Thanks for your help
Edited on 12 May 2014 - 09:34 PM
CometWolf #14
Posted 13 May 2014 - 07:39 AM
So what you've posted isn't an addon for other posts right?
That's exactly what it is.
The input password part would be the password function defined in the other posts.