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

Help with a bit of redstone outputs.

Started by phillykills, 23 December 2014 - 07:54 PM
phillykills #1
Posted 23 December 2014 - 08:54 PM
Hi, I'm in need of help as I am a bit of a noob at this and there is no tutorial (that I am aware of) that can help me.

I have a computer with a password that when entered correctly, outputs redstone current from the back to extend pistons.
Currently I have one password for opening it, and another for closing it.

I am looking for a way of toggling the current so I can use one password.
This is my current code:


while true do
term.clear()
term.setCursorPos(1,1)
print ("Please enter password:")
input = read ("*")
if input == "passord1" then
redstone.setOutput("back", true)
end
if input == "password2" then
redstone.setOutput("back", false)
end
end

If there is any way of setting a toggle output then please let me know.
Any help would be greatly appreciated.
Lyqyd #2
Posted 23 December 2014 - 10:36 PM
Well, there's a function in the redstone API to get the current output. If you took the current output, inverted it, and set the output to that, it would toggle the output. It would look like this:


redstone.setOutput("back", not redstone.getOutput("back"))
phillykills #3
Posted 24 December 2014 - 05:52 PM
Thanks man, this is so helpful, you're a life saver.
Thanks again.