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 › Re: Using mouseX/mouseY with custom int functions
Page Index Toggle Pages: 1
Re: Using mouseX/mouseY with custom int functions (Read 550 times)
Re: Using mouseX/mouseY with custom int functions
Apr 5th, 2010, 5:15pm
 
It's because you have semicolons after the if(......) statements....I would guess.

Also you have "return=0" which should be "return 0". Hope this helps.
Re: Using mouseX/mouseY with custom int functions
Reply #1 - Apr 5th, 2010, 5:35pm
 
Hi everyone,

Thanks for the syntax help Giles, I got it figured out (had an extra curly bracket in my void mouseClicked section..argh).  I'm going to post my now-working code here, just in case it ever serves to help anyone trying to do something similar.

Code:
/* This applet loads a 1020x600 .jpg with 4 distinct boxes ("regions") in it, and returns an integer between 1 and 4 depending on which "region" is clicked in, or a 0 if the click is not in any of the regions */

PImage a;  // Declare variable "a" of type PImage
int clickedBox;
int XofMouse;
int YofMouse;

void setup() {
 clickedBox = 0;
 size(1020, 600);
 a = loadImage("background.jpg");  
// Load the image into the program  
}

void draw() {
 image(a, 0, 0);
}

void mouseClicked() {
 XofMouse = mouseX;
 YofMouse = mouseY;
 clickedBox = whatBox(XofMouse, YofMouse);
 println(clickedBox);
}


int whatBox(int XofMouse, int YofMouse) {
if (XofMouse>310 && XofMouse<710 && YofMouse>380 && YofMouse<565) {return 1;}
else if (XofMouse>310 && XofMouse<710 && YofMouse>35 && YofMouse<220) {return 2;}
else if (XofMouse>35 && XofMouse<250 && YofMouse>36 && YofMouse<564) {return 3;}
else if (XofMouse>770 && XofMouse<985 && YofMouse>36 && YofMouse<564) {return 4;}
else {return 0;}
}
Page Index Toggle Pages: 1