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 › Converting boolean to int since 0116
Page Index Toggle Pages: 1
Converting boolean to int since 0116 (Read 611 times)
Converting boolean to int since 0116
Oct 3rd, 2006, 9:36am
 
Hello,

I have a program that's been using the Processing function int() to convert a boolean value to an integer (false=0, true=1).

Since the 0116 update, this code:

boolean b = true;
int a = int(b);

throws the following error:
Semantic Error: No applicable overload for a method with signature "parseInt(boolean)" was found in type "processing.core.PApplet". Perhaps you wanted the overloaded version "int parseInt(byte $1);" instead?

I tried int(byte(b)) as well, but got a similar error concerning parseByte().  Is there another function that will convert boolean to int?

Thanks for any help.
Re: Converting boolean to int since 0116
Reply #1 - Oct 3rd, 2006, 11:28am
 
boolean b=true;

int a=0;
if(b) a=1;
Re: Converting boolean to int since 0116
Reply #2 - Oct 3rd, 2006, 1:52pm
 
or, for the sake of brevity:

int a = b?1:0;
Re: Converting boolean to int since 0116
Reply #3 - Oct 3rd, 2006, 7:33pm
 
wow, i didn't know anyone was using that cast.. i removed it because supporting the ability to cast anything to anything else was a bit silly, and silly means extra unnecessary code. and as you can see, it's simple enough to do without the cast.
Re: Converting boolean to int since 0116
Reply #4 - Oct 4th, 2006, 6:14pm
 
Thanks everybody.
Now I feel foolish.  Smiley

For the record though, fry, the Processing reference still lists the int() function as accepting a boolean argument in 116+.  (http://processing.org/reference/int_.html)
Re: Converting boolean to int since 0116
Reply #5 - Oct 4th, 2006, 6:50pm
 
oh no, you shouldn't feel foolish at all. i just didn't think that anyone was using it. i'll make a note for casey to fix the reference.
Page Index Toggle Pages: 1