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 › problem with boolean method
Page Index Toggle Pages: 1
problem with boolean method (Read 552 times)
problem with boolean method
May 2nd, 2009, 9:33am
 
Hello! I just started to write my own processing application and I just faced a weird problem.

Inside a class I there is this  boolean method :
Code:
boolean mymethod(){
 for ( blah blah ){
    for ( blah blah ){
           if (i == mouseX && j == mouseY) {
                  return true ;
            } else {
                 return false ;      
       }
    }
 }
}


But when I try to run the code I get:
This method must return a result of type boolean.

Any ideas?
Thanks.
Re: problem with boolean method
Reply #1 - May 2nd, 2009, 9:48am
 
You don't provide full code, the inside test is a bit weird, as you would exit on the first loop...
I suppose that's not the case, so there are cases where you might reach the end of the method without going the "return" way.
In other words, you need to put a "return true;" (or false, depending on the wanted default) at the end of the function.
Re: problem with boolean method
Reply #2 - May 2nd, 2009, 10:00am
 
PhiLho  wrote on May 2nd, 2009, 9:48am:
In other words, you need to put a "return true;" (or false, depending on the wanted default) at the end of the function.


Yeap! That was it...thanks a lot!!!
Re: problem with boolean method
Reply #3 - May 2nd, 2009, 10:22am
 
Eh...sorry again, It seems that putting " return false; " at the end of the method always makes the method false.

I need to exit the loops and turn the method true when  " if (i == mouseX && j == mouseY) " is true.

I want to make a multitouch application. I just want to test it first with the mouse. So, when the mouse enters a picture, only then the picture can be moved.

I used this ( h  ttp://processing.org/learning/basics/sprite.html ) as an example and I just want to modify it for my purpose.

Code:
boolean pictouch( ){
 for ( float i = posx ; i<=posx + pic.width; i++){
    for ( float j = posy ; i<=posy + pic.height; i++){
                   if (i == mouseX && j == mouseY) {
                     return true ;
           }    
       }
    }
return false ;  
}
Re: problem with boolean method
Reply #4 - May 2nd, 2009, 11:12pm
 
At first glance I would say it is because you are using i instead of j as your loop conditions:
Code:

   for ( float j = posy ; i<=posy + pic.height; i++){


Aside from that, if you only need to know if the mouse is over an image, you can use
Code:

boolean pictouch() {
 return ( (mouseX >= piclocationx) &&
   (mouseX <= piclocationx+pic.width) &&
   (mouseY >= piclocationy) &&
   (mouseY <= piclocationy+pic.height) );
}
Re: problem with boolean method
Reply #5 - May 3rd, 2009, 8:13am
 
NoahBuddy wrote on May 2nd, 2009, 11:12pm:
At first glance I would say it is because you are using i instead of j as your loop conditions:
Code:

   for ( float j = posy ; i<=posy + pic.height; i++){


Well, I guess some people have the chance to see the proof that they are blind.  Grin
Thanks a lot...

One final question. I'll use the tuio plugin. So, in order to have a drag I believe I should check whether the first point of the cursor's path (using Vector path) is inside the image...Right?
Page Index Toggle Pages: 1