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.
Page Index Toggle Pages: 1
if() (Read 2447 times)
if()
Jun 14th, 2010, 7:04pm
 
To start, I'm pretty new to this so bear that in mind if I'm asking anything stupid here.

I'm trying to use if() to act upon int x being a certain value. Problem is, I can only ask if x is bigger than, or smaller than a particular value, not equal to. If I try something like:

if(x = 2)

then it returns the error "cannot convert from int to boolean, presumably because processing thinks I'm specifying the value of an integer in the middle there.

if(x < 2)
or
if(x > 2)

work fine, but how do I go about asking if something is exactly the value I want?

cheers!
Re: if()
Reply #1 - Jun 14th, 2010, 7:42pm
 
You're looking for "==", as in:
Code:
if (x == 2) {
// blah blah blah
}

(A lot of languages use just "=" for both assignment and equality testing, but Java isn't one of them.)
Page Index Toggle Pages: 1