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 › How to prevent an int increasing in each frame
Pages: 1 2 
How to prevent an int increasing in each frame (Read 2091 times)
Re: How to prevent an int increasing in each frame
Reply #15 - Nov 18th, 2009, 4:18am
 
Is there any other method of doing what we're trying to achieve?
Re: How to prevent an int increasing in each frame
Reply #16 - Nov 18th, 2009, 4:30am
 
Yes - there are lots of different approaches, including the one I have already described: add a property to Sprites and use this to record if a Sprite has been placed and check against it to ensure boxClick only gets increased once.

As I suggested before - there's no point to keep on asking the same question just because you can't implement the solutions that have been offered.
Re: How to prevent an int increasing in each frame
Reply #17 - Nov 18th, 2009, 8:16am
 
Okay, I'm trying your tactic of adding a property to the sprite class. please tell me if the logic is correct.

Code:

 for(int i =0; i< boxes.length; i++)
   {
 //method for locking image in place
   if(m_bDragged && x> boxes[i].x && x< (boxes[i].x+boxes[i].w-22) &&y <(boxes[i].y+boxes[i].h-20) && y >boxes[i].y)
   {
                         
 m_bDragged = false;    
 if((!m_bDragged) &&(i == boxID))
                          {
                           
    IncreaseBoxClick(i);
                            println(i);
   
}
  }
   }
           
   }
   
       
       int IncreaseBoxClick(int j)
      {
                 
           boxClick=j;
           //println(j);
           if(boxClick==(boxes.length-1))
           {
             bShowCorrect=true;
           }    
        return boxClick;  
      }


At the moment it only returns 'correct' if the last image is stored correctly. For example image 7 is stored in box 7, return correct.
Re: How to prevent an int increasing in each frame
Reply #18 - Nov 18th, 2009, 8:29am
 
Shocked
You clearly haven't understood much about Classes and where Class properties/variables should be declared.  Read this; it may help a little.  The property variable should be at the 'root' of your class and should preferably be a boolean, called something like 'isPlaced'.  When the Sprite is placed on a box you set the variable to 'true'.  You then only add to boxClick when the variable is false.

I don't hold out much hope of you being able to implement this; not least as I've made this exact same suggestion a couple of times already...  If you just want this thing built then I'd suggest you either ask someone very nicely, or stump up some cash...  If you're trying to learn then start by getting a good grasp of the basics.
Pages: 1 2