toggling with if{}else{} ?

Hi Folks,

I’m trying to toggle an integer (1 or 0) each time the function is called. This is my first play with OF but I’ve been successfully using this function in processing and arduino. Doesn’t seem to work in OF.
playLed remains 0. I know I’m calling playButt properly…

Probably missing something obvious?

void testApp::playButt(){

if(playLed==0){playLed=1;}else{playLed=0;}
}

Thanks!!
Alex

that should work i think.

if playLed is only 0 or 1, make it a boolean, so true or false.

then do

void testApp::playButt(){
playLed = !playLed;
}

that will toggle the state of the boolean

Hi Chris,

Thanks! But still not working… However, I found the problem:
The boolean is being toggled twice. I put a counter in the function and it was adding 2.

I moved the code into touchUp and sure enough, it is registering a double touchup!!:
I idea why it’s triggering twice?

Thanks for your help!!

void testApp::touchUp(ofTouchEventArgs &touch) {

if((touch.y>290)&&(touch.x<80)){

playLed=!playLed;counter++;// +2 added to counter on each touchUp (grrr)
}

}

If you’re using iOS here (or android maybe, too), there was a bug that some event notifications were triggered twice, this should already be corrected in the current develop branch.

Indeed I was using IOS.
Thanks!