We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi there, Anyone has an idea on how do I trigger events with a certain delay while the rest of the program continues running?
I have a event (beat) triggered at certain intervals with the help of the Clock class of the the beads library. At each of this event (beat) I trigger some new events with certain small delays. For instance the beat comes every second and should trigger 6 short events 50ms apart. The problem is that the "short" delays add to the "long" delay. So the main timer (the one second interval) is affected by the 6 50ms delay, which means the main timer event (beat) would be then 1,3seonds apart.
Is there any way how I can implement the short delay without affecting the main timer?
Thank you
Answers
For starters, I've got this thread and this example below:
http://forum.processing.org/two/discussion/1725/millis-and-timer
Thanks for the fast reply. This pretty much answered my question. But I have one more problem. I need a couple of timer, so I'm using a for loop to create all the tasks. But the task should depend on the index i of the for loop. But as the index i is a non final variable, I can't really use the index i in the run() function. It looks like this:
Is there a way to "finalize" the i by creating a new final variable?
Thanks
Surprisingly there is! Merely declare a
final
variable inside the loop block.Then assign the current iterator value to it! :ar!
Just for amusement, here's my 1st clunky attempt before realizing a mere
final
variable would do it! :O)I've extended the TimerTask
abstract class
as TimerTasked.The new constructor accepted a parameter as id for the instance:
P.S.: Bumped my original v1.22 to v1.3! Now it declares parameter sec as
final
. And accesses it inside run()! \m/