if within if - really stupid
in
Programming Questions
•
8 months ago
Hello!
I want to create a program that will accept the click of the mouse twice. first time, the user should click on an image and hear a sound. the sounds that I use are in an array (named test), and by each click, they are playing random. then, depending on which sound is heard, the user should click on an other image, and if he does well, another sound of applauses (sound7) will be heard. if the user click out of this image, a sound of failure will be heard. If it doesn't make scene, think I am trying to build a game for little children. every time they click on an ear image, they will hear a sound of an animal and they should match it with the correct animal image. it works pretty well, until the random sound of the clicks, but when i put a second "if" under the first, the program doesn't response. Here is my problematic part of the code:
void mousePressed(){
//if the user clicks on the first image, play random a sound
if (mouseX > 475 && mouseX < 525 && mouseY > 25 && mouseY < 75) {
int index = int( random(0,5) );
test[index].play();
//if the sound that played is the first one then and the user clicks on the right animal image, play song7 (applause)
if (test[index] == test[0]){
boolean mousePressed = true;
if (mousePressed == true && mouseX > 100 && mouseX < 300 && mouseY > 100 && mouseY < 250) {
song7.play();
//else if the user clicks out of this image, play sound8 (fail)
} else if (mousePressed == true && mouseX <100 && mouseX > 300 && mouseY < 100 && mouseY > 250) {
song8.play();
}
}
}
}
//if the user clicks on the first image, play random a sound
if (mouseX > 475 && mouseX < 525 && mouseY > 25 && mouseY < 75) {
int index = int( random(0,5) );
test[index].play();
//if the sound that played is the first one then and the user clicks on the right animal image, play song7 (applause)
if (test[index] == test[0]){
boolean mousePressed = true;
if (mousePressed == true && mouseX > 100 && mouseX < 300 && mouseY > 100 && mouseY < 250) {
song7.play();
//else if the user clicks out of this image, play sound8 (fail)
} else if (mousePressed == true && mouseX <100 && mouseX > 300 && mouseY < 100 && mouseY > 250) {
song8.play();
}
}
}
}
well, it doesn't get any error, it runs, but when i click in the right image, it does nothing at all... :( why?
of course there will be more than one images, but first I have to learn how to write the code...
any help appreciated! thanks in advance!
1