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

Title: Getting feedback from a button on a computer?

Started by DannySMc, 28 March 2013 - 11:06 PM
DannySMc #1
Posted 29 March 2013 - 12:06 AM
Okay so I am making a simple door locking system the code is below. I want to be able to make it so if a button is pressed on the other side of the door it would load another program so then the door would open for a bit so you can get out without having to press the computer and do the whole login again.

term.clear()
term.setCursorPos(1,1)
password = "qwerty"
print [[
Summotion Login System
------------------------------
Starting login, please wait
]]
textutils.slowPrint("******************************")
print [[
Summotion Login
--------------------
Enter Password:
]]
sleep(1)
input = read("*")
if input == password then
  textutils.slowPrint("Verrifying Password..............................")
  print("Password Accepted")
  sleep(2)
  print("Access Granted For 10 Seconds")
  rs.setOutput("bottom",true)
  sleep(10)
  rs.setOutput("bottom",false)
  os.shutdown()
else
  textutils.slowPrint("Verrifying Password.............................")
  print("Password Denied")
  sleep(2)
  term.clear()
  term.setCursorPos(1,1)
end
Goof #2
Posted 29 March 2013 - 01:51 AM
Well.. you have to make a parallel.waitForAll event. which constantly checks for input, on the computer, and for the redstone signal on the back of the computer.

i've actually coded your code so it works, but its not with that many comments…. (just an extra function "input", and a parallel + os.pullEventRaw

Spoiler


oldPull = os.pullEvent
os.pullEvent = os.pullEventRaw
	term.clear()
	term.setCursorPos(1,1)
	local password = "qwerty"
	local inputSide = "back" -- change to the side, the redstone signal would come from.
	openDoorProgram = "OpenDoor" -- the program name of the program, which opens the door, when the rs signal is received. 
	
function pass() -- your whole password system...
	print [[
	Summotion Login System
	------------------------------
	Starting login, please wait
	]]
	textutils.slowPrint("******************************")
	print [[
	Summotion Login
	--------------------
	Enter Password:
	]]
	sleep(1)
	input = read("*")
	if input == password then
	  textutils.slowPrint("Verrifying Password..............................")
	  print("Password Accepted")
	  sleep(2)
	  print("Access Granted For 10 Seconds")
	  rs.setOutput("bottom",true)
	  sleep(10)
	  rs.setOutput("bottom",false)
	  os.shutdown()
	else
	  textutils.slowPrint("Verrifying Password.............................")
	  print("Password Denied")
	  sleep(2)
	  os.shutdown() -- i would prefer to shutdown the computer, so the persone wouldnt be able to get directly into the shell, and edit this code, from the console.
	end
end
function input() -- checks the redstone signal.. if true, it would run a program.
	while not rs.getInput(inputSide) do sleep(0.5) end
	shell.run(openDoorProgram)
end

parallel.waitForAll(pass, input) --checking for input, and password
	
os.pullEvent = oldPull

i hope i could help.
GravityScore #3
Posted 29 March 2013 - 03:44 AM


function input() -- checks the redstone signal.. if true, it would run a program.
        while not rs.getInput(inputSide) do sleep(0.5) end
        shell.run(openDoorProgram)
end

Would be better written as:


function input() -- checks the redstone signal.. if true, it would run a program.
        while true do
            while not rs.getInput(inputSide) do os.pullEvent("redstone") end
            shell.run(openDoorProgram)
        end
end
Goof #4
Posted 29 March 2013 - 04:50 AM
Oh yeah. My fault
DannySMc #5
Posted 14 May 2013 - 06:49 AM
Oh yeah. My fault

Well.. you have to make a parallel.waitForAll event. which constantly checks for input, on the computer, and for the redstone signal on the back of the computer.

i've actually coded your code so it works, but its not with that many comments…. (just an extra function "input", and a parallel + os.pullEventRaw

Spoiler


oldPull = os.pullEvent
os.pullEvent = os.pullEventRaw
	term.clear()
	term.setCursorPos(1,1)
	local password = "qwerty"
	local inputSide = "back" -- change to the side, the redstone signal would come from.
	openDoorProgram = "OpenDoor" -- the program name of the program, which opens the door, when the rs signal is received.
	
function pass() -- your whole password system...
	print [[
	Summotion Login System
	------------------------------
	Starting login, please wait
	]]
	textutils.slowPrint("******************************")
	print [[
	Summotion Login
	--------------------
	Enter Password:
	]]
	sleep(1)
	input = read("*")
	if input == password then
	  textutils.slowPrint("Verrifying Password..............................")
	  print("Password Accepted")
	  sleep(2)
	  print("Access Granted For 10 Seconds")
	  rs.setOutput("bottom",true)
	  sleep(10)
	  rs.setOutput("bottom",false)
	  os.shutdown()
	else
	  textutils.slowPrint("Verrifying Password.............................")
	  print("Password Denied")
	  sleep(2)
	  os.shutdown() -- i would prefer to shutdown the computer, so the persone wouldnt be able to get directly into the shell, and edit this code, from the console.
	end
end
function input() -- checks the redstone signal.. if true, it would run a program.
	while not rs.getInput(inputSide) do sleep(0.5) end
	shell.run(openDoorProgram)
end

parallel.waitForAll(pass, input) --checking for input, and password
	
os.pullEvent = oldPull

i hope i could help.


this doesn't actually wait for the input for the button?:/