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 & HelpPrograms › Way to stop millis()
Page Index Toggle Pages: 1
Way to stop millis() ? (Read 1111 times)
Way to stop millis() ?
Dec 7th, 2009, 11:38pm
 
I'm using millis() as my way to keep score for my very beginner's video game.  However it's time so it just keeps on going up.

Is there a way I can stop the time at a certain point so when I go to show the score, it's a single number?

Hope that makes sense, I'm just a beginner!
Re: Way to stop millis() ?
Reply #1 - Dec 8th, 2009, 12:34am
 
You shouldn't really use millis for tracking a score.. It's a reference to how long your sketch has been running, used for timing stuff.

But if you insist, you should use a variable to store the millis();
that way, you can choose when to stop storing it, and thus getting a single number.

ie:

int startMillis; // Add this to start with a score of 0
int playerScore; // This is where the real score will be stored
void setup()
{
 startMillis = millis();
}
void draw()
{
 if(millis()-startMillis < 5000){ // If the timer has been running for 5 seconds, or whatever you want here to control the score being set
   doSomethingWithScore();
 }else{ // when that is done, print out the score, and exit
   println(playerScore);
   exit();
 }
}
void doSomethingWithScore()
{
 playerScore = millis() - startMillis;
}
Re: Way to stop millis() ?
Reply #2 - Dec 8th, 2009, 12:35am
 
what kind of game is it? a game where you have to survive a certain amount of  time? so thats also your score? instead of trying to stop the time, you can simply create another variable at the moment you want to show the score .
Re: Way to stop millis() ?
Reply #3 - Dec 8th, 2009, 1:33pm
 
I don't have to use millis(), but I found that to be the easiest thing to use, especially since I'm a beginner.

The game is a simple how long can you avoid being hit, and I though using millis() or something of the sort would be the best thing to give a number for score.
Re: Way to stop millis() ?
Reply #4 - Dec 8th, 2009, 1:43pm
 
so like i said, just store millis in another variable as long as the player is alive. stop it as soon as you are dead.

for example

if(alive==true)scrore=millis();
println(score);

Page Index Toggle Pages: 1