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 › if sentence and 'flags'
Page Index Toggle Pages: 1
if sentence and 'flags' (Read 487 times)
if sentence and 'flags'
Feb 8th, 2006, 9:05am
 
Hi,

In my void draw() I have an if sentence, where I only want to generate a list of numbers once when the mouse is not pressed. Is there a way to set a flag in the if loop to stop random() from looping while the mouse is not pressed?

 if(mousePressed==true) {
     // the t-values are set to 0  
     tX = 0; tY = 0; tZ = 0;
     
     
 } else {
     for(int j=0; j<numParam; j++){
       p[j] = random(1); // generate random numbers between 0 and 1  ONE    
                                   //TIME ONLY
     }
           
 }
Re: if sentence and 'flags'
Reply #1 - Feb 8th, 2006, 11:44am
 
The following generates the list only once if initially the mouse is not pressed, and only once between mouse presses:

boolean isGenerated = false;
if(mousePressed) {  
// the t-values are set to 0  
tX = 0; tY = 0; tZ = 0;
isGenerated = false;
}
else if (!isGenerated) {
 for(int j=0; j<numParam; j++){
   p[j] = random(1);
 }
 isGenerated = true;
}
Page Index Toggle Pages: 1