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 › Building a trigger
Page Index Toggle Pages: 1
Building a trigger (Read 662 times)
Building a trigger
Feb 22nd, 2010, 8:34am
 
Hello people.

Id like to build a trigger. That means when i release  a key  a boolean "trigger" switches on and when i release it again (after being pressed) it turns off. Something like that:


Code:

void keyReleased() {
if(keyCode== CONTROL) {
if (trigger) {
     trigger = false;
if (!trigger)
     trigger = true;
}
}



The problem with that code is that the trigger switches to false and BECAUSE its false it switches back to on in the same time...
Re: Building a trigger
Reply #1 - Feb 22nd, 2010, 8:49am
 
you could add else before if(!trigger)
which would give you:
Code:

boolean trigger;

void keyReleased() {

 if(keyCode== CONTROL) {
   if (trigger) {
     trigger = false;
   } else if (!trigger) {
     trigger = true;
   }
 }
 println("trigger "+trigger);
}


or less code:

Code:

boolean trigger;

void keyReleased() {

 if(keyCode== CONTROL) {
   trigger = !trigger;
 }
 println("trigger "+trigger);
}
Re: Building a trigger
Reply #2 - Feb 22nd, 2010, 12:07pm
 
Thanks sojamo! It works.
Page Index Toggle Pages: 1