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 & HelpPrograms › Re: Help! Mouse pressed function!!
Page Index Toggle Pages: 1
Re: Help! Mouse pressed function!! (Read 649 times)
Re: Help! Mouse pressed function!!
Apr 15th, 2010, 9:47am
 
Without even going to see more, I notice: if (startup = true) {
That's a trap lot of coders fall into.
Well, mostly in C/C++, because in Java the cases where it is legal are rare (variable must be boolean), but you just hit it!

The problem is that you wrote = (assignment) instead of == (equality test). So startup becomes true as soon as it goes to false...

Note: when you have a boolean, just test like:
if (startup) {
it is cleaner (in my eyes) and less prone to this issue!
Re: Help! Mouse pressed function!!
Reply #1 - Apr 15th, 2010, 10:04am
 
Two problems here.  First:

Quote:
if (mousePressed == true) {
  if ((mouseX > 0) && (mouseX < 400) && (mouseY>0) && (mouseY> 400)) {


I think you might have meant mouseY<400; though in actual fact you might have been better off with something along the lines of:

Code:
if (mousePressed == true) {
  if ((mouseX > 0) && (mouseX < width) && (mouseY>0) && (mouseY< height)) {


Then the code will work no matter what size your sketch window Wink

Second and more fundamental problem:

Quote:
if (startup = true) {
 // snip
}
else if (level1 = true) {
 // snip
}


A single = sign is the assignment operator; so what you're doing in the if condition is setting the value of startup to true; which is why your else doesn't get executed.  What you need is:

Code:
if (startup == true) { 



Or you can in fact abbreviate boolean true conditions to simply:

Code:
if (startup) { 



Roll Eyes PhiLho beat me to it; though he didn't mention the mistake in your mousePressed condition Tongue
Re: Help! Mouse pressed function!!
Reply #2 - Apr 17th, 2010, 3:52pm
 
thank you to all who answered.
Page Index Toggle Pages: 1