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

Computer used as a timer, repeat and wait for input

Started by CanadasElite, 13 June 2013 - 10:05 AM
CanadasElite #1
Posted 13 June 2013 - 12:05 PM
I'm trying to use a computer to set a redstone output for a certain amount of time and be able to execute it more than once and wait for an imput.
Here's the code, this is as far as I got before I realized I can't do this with what I know and it used to be a 'when loop' not a repeat and this code currently doesn't work but the when one did.
I thought about using coroutine but I have no idea how to use that one either. The use of this will be for a survival event on a tekkit server (the new tekkit pack) for doors and windows to close for a certain ammount of time.
Lyqyd #2
Posted 13 June 2013 - 12:39 PM
Split into new topic.


while true do
  os.pullEvent("redstone") --wait for a change in redstone
  if rs.getInput("top") then
    rs.setOutput("left", true)
    sleep(10)
    rs.setOutput("left", false)
    sleep(10)
  end
end
CanadasElite #3
Posted 13 June 2013 - 01:21 PM
Thanks this helps a lot. It works for the first imput but I have to terminate it then restart the program, which in my case can't happen really. I tried tweaking it with that repeat loop but I couldn't get it to work. What I want it to do is when a button is pushed it closes a door/barrier for 20 or 30 seconds and have it repeat that without having to open a console.
Lyqyd #4
Posted 13 June 2013 - 02:01 PM
You may have been trying to use it too quickly. Try taking out the second sleep(10).
CanadasElite #5
Posted 13 June 2013 - 02:15 PM
Ah, I guess I was, thanks this really helps.