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 › Millis never stops!
Page Index Toggle Pages: 1
Millis never stops! (Read 637 times)
Millis never stops!
Oct 16th, 2006, 2:53am
 
I would like to start the "millis()" when I push any key, but the processing begin the "millis()" no matter when I want to start, the "millis()" begin as I push the "play". For example, a processing starts with a text informing something, then asks to push some key to start the processing, but the program is done to start the "millis()" only when I push some key, but it is not happening. The "millis()" always begin when the program begin, no matter of "loop()" or "no Loop()".

So is there anything wrong with "millis()"? Or do I did anything wrong?

Thanks.

Nintendo.
Re: Millis never stops!
Reply #1 - Oct 16th, 2006, 7:36am
 
millis is the number of milliseconds since the applet started, so you can't stop it, nor pause it.
but you can make your own variable, where myMillis is your new millisecond counter

Code:

int myMillis = 0;
int myPaused = 0;
int myDiff = 0;
boolean paused = false;

void setup()
{
size(300,300);
}

void draw()
{
if(!paused) updateMillis();
println(myMillis);
}

void updateMillis()
{
myMillis = millis()-myDiff;
}

void keyPressed()
{
if(!paused) myPaused = millis();
paused = true;
}

void keyReleased()
{
paused = false;
myDiff += millis()-myPaused;
}
Page Index Toggle Pages: 1