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

[Lua] Redstone timer

Started by xxx, 02 August 2012 - 06:37 PM
xxx #1
Posted 02 August 2012 - 08:37 PM
Hello!
I've tried to make a program which makes the computer emit a constant redstone signal on the right side, and a pulsing signal from the back.
I don't seem to get it right!
Help would be very appreciated! Thank you!

PS; My try:

while true do
rs.setOutput("right",true)
rs.setOutput("back",true)
os.sleep(5)
rs.setOutput("back",false)
end
MysticT #2
Posted 02 August 2012 - 08:43 PM
You need to add a sleep after setting the output to false, or it will inmediately turn it on again. Also, you don't need the first rs.setOutput inside the loop:

rs.setOutput("right", true)
while true do
  rs.setOutput("back", true)
  sleep(2.5)
  rs.setOutput("back", false)
  sleep(2.5)
end
Remember that the time passed to sleep is in seconds, so it sets the output to true, waits 2.5 seconds, turns it off, and waits another 2.5 seconds.
xxx #3
Posted 02 August 2012 - 09:16 PM
Well, thank you! That was pretty obvious, but when you sit and code for a longer time, it may begin to become hard to find the right way.
MysticT #4
Posted 02 August 2012 - 09:21 PM
Well, I didn't see the error at first. It's a really common error to forget that sleep :ph34r:/>/>