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

Making a loop function to open a door.

Started by ChasedMonkey, 07 September 2012 - 08:00 PM
ChasedMonkey #1
Posted 07 September 2012 - 10:00 PM
So im new to LUA, I know the basics of java. I was trying to make a program that, when run, would check if a redstone output was true, and if it was true set it to false, if it was false set it to true. But im not sure exactly how to check its original state, here is what i have so far.
Spoiler
  1. if
  2. redstone.setOutput("back", true)
  3. then
  4. redstone.setOutput("back", true) == redstone.setOutput("back", false)
  5. else
  6. redstone.setOutput("back", false) == redstone.setOutput("back", true)
  7. end
I tried making line 2 say "redstone.Output("back", true)" but I had no sucess.

So the question is, how do i make this work?
Cranium #2
Posted 07 September 2012 - 10:24 PM
You can use this:
 if rs.getOutput("back") then rs.setOutput("back",false) else rs.setOutput("back",true) end 
It checks if it's already outputting a signal, then if so, it shuts it off. You can learn more about the Redstone API by clicking on the link.
ChasedMonkey #3
Posted 08 September 2012 - 11:54 PM
OH getOutput, thats where i was having issues. Thanks :D/>/>
Lyqyd #4
Posted 09 September 2012 - 06:27 PM
Also, rs.setOutput("back", not rs.getOutput("back")) would always toggle the output.