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

Running a program for a certain amount of time?

Started by lieudusty, 17 August 2012 - 02:08 PM
lieudusty #1
Posted 17 August 2012 - 04:08 PM
Hi everyone! =D

This is probably a noob question but how do I make a program run for a certain amount of time then stop? Thanks.
Cranium #2
Posted 17 August 2012 - 04:13 PM
It depends on the program running. Some cases you can just have it sleep for a certain amount of time, and os.shutdown(), other times you would need to use some timers and os.pullEvent()… What kind of program are you running? Could you post the code?
lieudusty #3
Posted 17 August 2012 - 04:23 PM
Well I wanted to continuously print something for lets say 10 seconds then stop.
ardera #4
Posted 17 August 2012 - 04:34 PM
Code:

function a()
  shell.run("theprogram")
end
function b()
  sleep(10)
end
parallel.waitForAny(a, :(/>/>
(This is a program to run the program "theprogram" for 10 secs)
Cranium #5
Posted 17 August 2012 - 04:37 PM
Code:

function a()
  shell.run("theprogram")
end
function b()
  sleep(10)
end
parallel.waitForAny(a, :(/>/> --your code here called for "B", and we needed "b"
(This is a program to run the program "theprogram" for 10 secs)

Slight correction.