We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Overcoming second() 0-59 variables to 'loop'
Page Index Toggle Pages: 1
Overcoming second() 0-59 variables to 'loop' (Read 614 times)
Overcoming second() 0-59 variables to 'loop'
Nov 14th, 2009, 6:22am
 
Hi again

Am looking to loop an event based on the second() method which from referring to documentation: values from 0-59.

Am implementing a 'tick' sound in time with a second hand.
This has successfully implemented except once second hand reaches '0' at top again the sound stops. I think it has something to do with the 0-59 variables but am unsure as to how to overcome.

Here is the code:

Code:
  if(second() > lastTick)
{
snip.trigger();
lastTick = second();
}


The sound stops at 0 (at top). Small buffer underrun but this *should* not matter.

Have been thinking of implementing things like:

Code:
  if(second() > lastTick)
{
[b] firstTick = second();[/b]
snip.trigger();
lastTick = second();
}


to no avail.

thanks in advance, calum
Re: Overcoming second() 0-59 variables to 'loop'
Reply #1 - Nov 14th, 2009, 6:48am
 
Try it like this:

Code:

if(second() >= (lastTick+1)%60)
{
snip.trigger();
lastTick = second();
}

Re: Overcoming second() 0-59 variables to 'loop'
Reply #2 - Nov 14th, 2009, 7:01am
 
The code works except at around 57-59 second mark the sound overlaps and makes an awful sound. I'm thinking the fact of the second() resetting itself may be an issue.

Is there a workaround for this? Perhaps a debugger?
Re: Overcoming second() 0-59 variables to 'loop'
Reply #3 - Nov 14th, 2009, 7:31am
 
woo! solved it. the > symbol not required.

here code:

Code:
if(second() == (lastTick+1)%60)
{
snip.trigger();
lastTick = second();
}


thanks again
Page Index Toggle Pages: 1