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

Help with door program

Started by skyman939, 30 May 2013 - 05:35 AM
skyman939 #1
Posted 30 May 2013 - 07:35 AM
im trying to make a program that will open and close a red power door



i need it to pulse three times to open and close the door
i need it to work from an external computer to an advanced computer inside my locked down base.
so i could log in and then tell it to open then have it auto close like 15 seconds after it opens


so ultimately needs

password
to open after password is entered
and then close a little later



anyone thats willing to help thanks!!!!!
Cranium #2
Posted 30 May 2013 - 10:33 AM
Well, it sounds like you need us to write the program for you. That's not why we are here. Granted, it is a simple program, but we would much rather teach you how to write it rather than handing you a program.

To start off though, with passwords, you can do that quite easily.

local password = "password" -- set the password
local input = read("*") -- get input fromt he user, but replacing their input with "*" when typing
if input == password then -- check that what the user entere is the same as the set password
    --do stuff here
end
That is the simplest password system, and you can definitely expand upon it.
For redstone pulses, take a look at the Redstone API. This will help you get started on making the door lock you want.
Let us know if you have any trouble!
Apfeldstrudel #3
Posted 30 May 2013 - 12:10 PM
Here you go!


os.pullEvent = os.pullEventRaw
local password = "Password"-- edit for real password
local input = ""
local side = "left"--edit for right top or whatever
while true do
  term.setCursorPos(5,5)
  print("Insert password below:")
  term.setCursorPos(5,6)
  input = read("*")
  if input == password then
	term.setCursorPos(5,8)
	print("Success!")
	rs.setOutput(side,true)
	sleep(3)
	rs.setOutput(side, false)
	term.clear()
	term.setCursorPos(1,1)
  else
	term.setCursorPos(5,8)
	print("Wrong password!")
	sleep(0.75)
	term.clear()
	term.setCursorPos(1,1)
  end
end

Cranium #4
Posted 30 May 2013 - 12:41 PM
Here you go!
Well thank you for completely missing the point.

By the way, your code is not what he asked for. He needs the redstone to pulse three times for the door to open and close.

@skyman939: For something to repeat a number of times, you will want a for loop.

for i = 1, 3 do
    rs.setOutput(side, true)
    sleep(.1)
    rs.setOutput(side, false)
    sleep(.1)
end
This would pulse the redstone output on teh specified side three times.
As a breakdown, let me explain the loop:

for iterator = start, stop, step do
    --do stuff
end
The 'iterator' is the number that increases or decreases at every specified 'step', starting at 'start' until the 'stop'.