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 › return boolean type not working
Page Index Toggle Pages: 1
return boolean type not working? (Read 704 times)
return boolean type not working?
Mar 21st, 2007, 4:09am
 
The following code is supposed to flip a drawing mode switch. It seems to look ok...


public boolean drawMode(boolean drawMode2){
   if(keyPressed && key == 32){
     drawMode2 = !drawMode2;
     return drawMode2;
   }
 }

Semantic Error:
The method "boolean drawMode(boolean drawMode2);" must contain a return statement with an expression compatible with type "boolean".


This is an example from  http://processing.org/reference/return.html

int timestwo(int dVal) {
 dVal = dVal * 2;
 return dVal;
}

What rule am i miss here? Thanks in advance.
Jason
Re: return boolean type not working?
Reply #1 - Mar 21st, 2007, 6:29am
 
you return statement is inside an if-clause. you have to either move it out of there or include another default return after the end of the if-clause (or inside else).
Re: return boolean type not working?
Reply #2 - Mar 23rd, 2007, 2:56pm
 
oh..right! thanks a lot.
Page Index Toggle Pages: 1