Logic Problem in Clickable Menu
in
Programming Questions
•
1 month ago
Hi,
I am creating a clickable menu which I later put into an Android phone. Here, I have created 4 dummy menu and each menu has its own images and sounds ( currently sound is not there). So the problem is when I click on button '0' it clicks button '0' zero of every menu and click until it gets the last menu. So when I click the button '0' of first menu1 it should go to the menu2 but it goes to menu4.
In every menu button number "10" is set to prev menu but it is also not working and button 11 is set for MAIN MENU which is working fine. Each button will lead to some MENU so here when you click on button '0' it open another menu and if you click on button '0' of this menu it will open some other menu and so on.
If you are not able to understand my problem you can simply try the application and try clicking on the button zero.
I know there is some logic problem which I am not able to see so please help me to fix this. It is really urgent
----------------------------------------------
P.S. I know I could have create the class of the "MENU" but I didn't do because I wanted to make it simple and understandable.
-----------------------------------------------
- //import apwidgets.*;
- //APMediaPlayer[] player;
- int flag, boxsize=200;
- PImage[] img1 = new PImage[12]; // LEVEL 1 IMAGES
- PImage[] img2 = new PImage[12]; // LEVEL 2 IMAGES
- PImage[] img3 = new PImage[12]; // LEVEL 3 IMAGES
- PImage[] img4 = new PImage[12]; // LEVEL 4 IMAGES
- int m1=0, m2=0, m3=0, m4=0;
- void setup()
- {
- size(600, 800);
- smooth();
- /*/---------------AUDIO-----------------------------
- for (int k=0;k<12;k++) {
- player[k]= new APMediaPlayer(this);
- }
- //----------------LOADING AUDIO FILE--------------
- for (int k=0;k<12;k++) {
- player[k].setMediaFile("Greeting_5.mp3");
- }*/
- //----------------IMAGE LEVEL 1--------------------------------
- for (int j=0;j<12;j++) {
- String str =j+".jpg";
- if (str!=null) {
- img1[j] = loadImage(str);
- println(str);
- }
- }
- //------------------IMAGE LEVEL 2----------------------------------
- for (int j=0;j<12;j++) {
- String str ="a" + j+".jpg";
- if (str!=null) {
- img2[j] = loadImage(str);
- println(str);
- }
- }
- //------------------IMAGE LEVEL 3----------------------------------
- for (int j=0;j<12;j++) {
- String str ="b" + j+".jpg";
- if (str!=null) {
- img3[j] = loadImage(str);
- println(str);
- }
- }
- //------------------IMAGE LEVEL 4----------------------------------
- for (int j=0;j<12;j++) {
- String str ="c" + j+".jpg";
- if (str!=null) {
- img4[j] = loadImage(str);
- println(str);
- }
- }
- //----------------------------------------------------------------
- }
- /*/---------------
- public void onDestroy() {
- super.onDestroy();
- for (int k=0;k<12;k++) {
- if (player != null) {
- player[k].release();
- }
- }
- }
- //----------------*/
- void draw()
- {
- background(#00FF4E);
- pushStyle();
- textMode(CENTER);
- textSize(40);
- text("ERROR SCREEN", width/4,height/2);
- popStyle();
- if (m1==0) {
- menu1();
- }
- if (m2==1 )
- {
- menu2();
- }
- if (m3==1 )
- {
- menu3();
- }
- if (m4==1 )
- {
- menu4();
- }
- }
- //----------------------------------------------------------------------------
- void menu1() {
- // if ( player[0]==null) {
- // player[1].start();
- // }
- for (int x = 0; x < 3 ; x++) {
- for (int y=0; y<4; y++) {
- int i = x + y*3;
- fill(#002CFC);
- stroke(0);
- strokeWeight(7);
- rect(x*boxsize, y*boxsize, boxsize, boxsize);
- if (img1[i]!= null) {
- imageMode(CENTER);
- image(img1[i], x*boxsize+boxsize/2, y*boxsize+boxsize/2); // LEVEL 1 IMAGES
- }
- if ( x*boxsize < mouseX && mouseX < x*boxsize+boxsize && y*boxsize < mouseY && mouseY < y*boxsize+boxsize)
- {
- fill(255, 0, 0, 50);
- noStroke();
- rect(x*boxsize, y*boxsize, boxsize, boxsize);
- if (mousePressed)
- {
- if (i==0)
- {
- m1=1;
- m2=1;
- println("MENU 2 " + m2);
- }
- }
- }
- //textMode(CENTER);
- fill(0);
- textSize(24);
- text(i, x*boxsize+boxsize/2, y*boxsize+3*boxsize/4+30);
- }
- }
- }
- //--------------MENU 2------------------------------------------------------
- void menu2() {
- // if ( player[0]==null) {
- // player[1].start();
- // }
- for (int x = 0; x < 3 ; x++) {
- for (int y=0; y<4; y++) {
- int i = x + y*3;
- fill(#FAA700);
- stroke(0);
- strokeWeight(7);
- rect(x*boxsize, y*boxsize, boxsize, boxsize);
- if (img2[i]!= null) {
- imageMode(CENTER);
- image(img2[i], x*boxsize+boxsize/2, y*boxsize+boxsize/2);// LEVEL 2 IMAGES
- }
- if ( x*boxsize < mouseX && mouseX < x*boxsize+boxsize && y*boxsize < mouseY && mouseY < y*boxsize+boxsize)
- {
- fill(255, 0, 0, 50);
- noStroke();
- rect(x*boxsize, y*boxsize, boxsize, boxsize);
- if (mousePressed)
- {
- if (i==0)
- {
- m1=1;
- m3=1;
- println("GO NEXT MENU 3");
- }
- if (i==10 )
- {
- m1=1;
- m2=0;
- m3=0;
- m4=0;
- println("GO PREV MENU m1 " + m1 );
- }
- if (i==11 )
- {
- m1=0;
- m2=0;
- m3=0;
- m4=0;
- println("GO MAIN MENU m1 " + m1 );
- }
- }
- }
- //textMode(CENTER);
- fill(0);
- textSize(24);
- text(i, x*boxsize+boxsize/2, y*boxsize+3*boxsize/4+30);
- if (i==10 )
- {
- text("PREV MENU", x*boxsize+30, y*boxsize+3*boxsize/4);
- }
- if (i==11 )
- {
- text("MAIN MENU", x*boxsize+30, y*boxsize+3*boxsize/4);
- }
- }
- }
- }
- //---------------MENU 3-----------------------------------------------------
- void menu3() {
- // if ( player[0]==null) {
- // player[1].start();
- // }
- for (int x = 0; x < 3 ; x++) {
- for (int y=0; y<4; y++) {
- int i = x + y*3;
- fill(#00ADFA);
- stroke(0);
- strokeWeight(7);
- rect(x*boxsize, y*boxsize, boxsize, boxsize);
- if (img3[i]!= null) {
- imageMode(CENTER);
- image(img3[i], x*boxsize+boxsize/2, y*boxsize+boxsize/2); // LEVEL 3 IMAGES
- }
- if ( x*boxsize < mouseX && mouseX < x*boxsize+boxsize && y*boxsize < mouseY && mouseY < y*boxsize+boxsize)
- {
- fill(255, 0, 0, 50);
- noStroke();
- rect(x*boxsize, y*boxsize, boxsize, boxsize);
- if (mousePressed==true)
- {
- if (i==0)
- {
- m1=1;
- m4=1;
- println("GO NEXT MENU 4 m4 " + m4 );
- }
- if (i==10 )
- {
- m2=1;
- m1=1;
- m3=0;
- m4=0;
- println("GO PREV MENU m2 " + m2 );
- }
- if (i==11 )
- {
- m1=0;
- m2=0;
- m3=0;
- m4=0;
- println("GO MAIN MENU m1 " + m1 );
- }
- }
- }
- //textMode(CENTER);
- fill(0);
- textSize(24);
- text(i, x*boxsize+boxsize/2, y*boxsize+3*boxsize/4+30);
- if (i==10 )
- {
- text("PREV MENU", x*boxsize+30, y*boxsize+3*boxsize/4);
- }
- if (i==11 )
- {
- text("MAIN MENU", x*boxsize+30, y*boxsize+3*boxsize/4);
- }
- }
- }
- }
- //------------------MENU 4--------------------------------------------------
- void menu4() {
- // if ( player[0]==null) {
- // player[1].start();
- // }
- for (int x = 0; x < 3 ; x++) {
- for (int y=0; y<4; y++) {
- int i = x + y*3;
- fill(#FFF700);
- stroke(0);
- strokeWeight(7);
- rect(x*boxsize, y*boxsize, boxsize, boxsize);
- if (img4[i]!= null) {
- imageMode(CENTER);
- image(img4[i], x*boxsize+boxsize/2, y*boxsize+boxsize/2); // LEVEL 4 IMAGES
- }
- if ( x*boxsize < mouseX && mouseX < x*boxsize+boxsize && y*boxsize < mouseY && mouseY < y*boxsize+boxsize)
- {
- fill(255, 0, 0, 50);
- noStroke();
- rect(x*boxsize, y*boxsize, boxsize, boxsize);
- if (mousePressed)
- {
- if (i==0)
- {
- m1=1;
- //m5=0; if I 'll add any more menu
- println("GO NEXT MENU 5");
- }
- if (i==10 )
- {
- m3=1;
- m1=1;
- m2=0;
- m4=0;
- println("GO PREV MENU m3" + m3 );
- }
- if (i==11 )
- {
- m1=0;
- m2=0;
- m3=0;
- m4=0;
- println("GO MAIN MENU" );
- }
- }
- }
- //textMode(CENTER);
- fill(0);
- textSize(24);
- text(i, x*boxsize+boxsize/2, y*boxsize+3*boxsize/4+30);
- if (i==10 )
- {
- text("PREV MENU", x*boxsize+30, y*boxsize+3*boxsize/4);
- }
- if (i==11 )
- {
- text("MAIN MENU", x*boxsize+30, y*boxsize+3*boxsize/4);
- }
- }
- }
- }
1