# How to do a true or false game?

**URL:** <https://discourse.processing.org/t/how-to-do-a-true-or-false-game/15963>\
**Category:** Coding Questions\
**Created:** [November 29, 2019, 11:14pm UTC](https://discourse.processing.org/t/how-to-do-a-true-or-false-game/15963 "2019-11-29T23:14:04Z")\
**Posts on this page:** 17\
**Page:** 2

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [January 24, 2020, 8:54am UTC](https://discourse.processing.org/t/how-to-do-a-true-or-false-game/15963/21 "2020-01-24T08:54:51Z")

</div>

i think i see flashing here after click on ‘NEXT QUESTION’ ( in resultScreen() )

- the ```mousePressed```` there sets flag 3
- `actOnFlag` increase to next question and set flag 0  
but in that one loop NOT use background ( so the draw background is shown )

* * *

about there also i see a problem with `pushStyle();`  
better get rid of them as not needed

* * *

```auto
  } else if (flag == 3) {
// pushStyle();    
    background(255); //KLL
//KLL draw_zurueck_button();

    index++;
    if ( index >= text2.length ) state=7;
    flag=0;

```

* * *

at the end ( state 7 ) there is no operation possible?  
not nice on a fullscreen app. [ESC]

---

<div class="post-metadata">

**Author:** ![Ladan](https://avatars.discourse-cdn.com/v4/letter/l/dbc845/32.png) [@Ladan](https://discourse.processing.org/u/Ladan)\
**Post date:** [January 25, 2020, 2:05pm UTC](https://discourse.processing.org/t/how-to-do-a-true-or-false-game/15963/22 "2020-01-25T14:05:58Z")

</div>

the flashing is gone now, but as soon as I press the quiz button for the second time( after i did it once) i get an index out of bounds exception in line 114:

```auto
int state = 0;
color green = color(72, 255, 0);
color red = color(255, 17, 0);
color lightblue = color(3, 182, 252);

int flag = 0;

// 3 parallel arrays 

String[] text1 = { 
  "1. Aussage:", 
  "2. Aussage:", 
  "3. Aussage:", 
  "4. Aussage:", 
  "5. Aussage:", 
  "6. Aussage:", 
};

String[] text2 = { 
  "Wir haben einen nicht gelisteten Helfer.", 
  " Wir sind das erste Mal dabei.", 
  "Unser Team besteht nur aus Leuten aus der 7. Klasse.", 
  " Unserer ITler ist der coolste.", 
  "Beim letzten Wettkampf kamen wir in die Top 5.", 
  "Unsere Schule stellt ein anderes Team.", 
};

int[] correct = {
  1, 
  2, 
  2, 
  1, 
  2, 
  1, 
};

// index for all 3 
int index = 0; 

String QUIZ = "Q\nU\nI\nZ\n";

int x1=100, y1=100, w1=250, h1=250; //Button oben links
int x2=1570, y2=100, w2=250, h2=250; //Button oben rechts
int x3=100, y3=750, w3=250, h3=250; //Button unten links
int x4=1570, y4=750, w4=250, h4=250; //Button unten rechts
int x5=80, y5=910, w5=250, h5=100; // Button zurück
int x6=860, y6=0, w6=200, h6=1080; //Button Quiz
int x7=260, y7=290, w7=500, h7=500; //Quiz left Button
int x8=1160, y8=290, w8=500, h8=500; //Quiz right Button

void drawMainButtons() { // _______ stat 0 only
  if ( over(x1, y1, w1, h1) ) stroke(200, 0, 0); 
  else stroke(0);
  rect(x1, y1, w1, h1);
  if ( over(x2, y2, w2, h2) ) stroke(200, 0, 0); 
  else stroke(0);
  rect(x2, y2, w2, h2);
  if ( over(x3, y3, w3, h3) ) stroke(200, 0, 0); 
  else stroke(0);
  rect(x3, y3, w3, h3);
  if ( over(x4, y4, w4, h4) ) stroke(200, 0, 0); 
  else stroke(0);
  rect(x4, y4, w4, h4);
  if ( over(x6, y6, w6, h6) ) stroke(200, 0, 0); 
  else stroke(0);
  rect(x6, y6, w6, h6);
  draw_quiz_text();
}

void draw_zurueck_button() { //_ state 1,2,3
  fill(0, 0, 200);
  if ( over(x5, y5, w5, h5) ) stroke(200, 0, 0); 
  else stroke(0);
  rect(x5, y5, w5, h5);

  fill(184, 18, 18);
  textSize(55);
  stroke(0);
  text("zurück", x5 + 35, y5 + 68);
  textSize(40);
  fill(0, 0, 200);
}

void draw_quiz_text() {

  fill(184, 18, 18);
  textSize(150);
  stroke(0);
  textLeading(250);
  textAlign(CENTER);
  text(QUIZ, x6 + 95, y6 + 220);
  textAlign(LEFT);
  textSize(40);
  fill(0, 0, 200);
}

void actOnFlag() {
  if (flag == 0) {
    // Question 1
    pushStyle();
    background(255);
    fill(255, 0, 0);
    rect (700, 300, 300, 300);
    fill(0, 255, 0);
    rect (300, 300, 300, 300);
    fill(0, 0, 0);
    text(text1[index], 600, 150);
    text(text2[index], 350, 190);
    textSize(32);
    fill(0, 51, 0);
    text("WAHR", 400, 450);
    textSize(32);
    fill( 128, 0, 0);
    text("FALSCH", 800, 450);
    pushStyle();
  } else if (flag == 1 || flag == 2) {  
    //
    resultScreen();
  } else if (flag == 3) {
    background(255);   

    draw_zurueck_button();

    
    flag=0;
    index++;
    if ( index >= text2.length ) state=7;
    flag=0;
  } else {
    background(255);
    textSize(32);
    fill(255, 0, 0);
    text("Error in actOnFlag: "+flag, 600, 150);
  }
}//func 

void setup() {
  fullScreen();
  //size(1920, 1200);
  fill(0, 0, 200);
  strokeWeight(10);
}

void draw() {
  background(68, 235, 7);

  if ( state == 0 ) drawMainButtons(); 

  if ( state == 1 ) draw_back_button_and_some_text1();
  if ( state == 2 ) draw_back_button_and_some_text2();
  if ( state == 3 ) draw_back_button_and_some_text3();
  if ( state == 4 ) draw_back_button_and_some_text4();

  if ( state == 6 ) actOnFlag();
  if ( state == 7 ) {
   
    textSize(32);
    text("Das war's", 600, 150);
    text("Danke für's mitmachen", 600, 200);
    draw_zurueck_button();
    
  }
}

void mousePressed() {
  if ( state == 0 ) {
    if ( over(x1, y1, w1, h1) ) state = 1;
    if ( over(x2, y2, w2, h2) ) state = 2;
    if ( over(x3, y3, w3, h3) ) state = 3;
    if ( over(x4, y4, w4, h4) ) state = 4;
    if ( over(x6, y6, w6, h6) ) state = 6;
  } else {
    if ( over(x5, y5, w5, h5) ) state = 0;
  }
    

  println("MouseX: " + mouseX + " MouseY: " + mouseY + " Flag: " + flag);

  //------------------------
  if (flag == 0) {
    // Question 1
    if (mouseX>300 && mouseX < 600 && mouseY >300 && mouseY <600) {
      flag = 1;
    }
    if (dist(mouseX, mouseY, 849, 450)<125) {
      flag = 2;
    }
  }
  //------------------------
  // Two result screens with a "Next button"
  else if (flag == 1) {
    // Correct 
    if (mouseX>600 && mouseX < 900 && mouseY >300 && mouseY <600) {
      flag = 3; // both proceed to Question 2
    }
  } else if (flag == 2) {
    // Wrong 
    if (mouseX>600 && mouseX < 900 && mouseY >300 && mouseY <600) {
      flag = 3; // both proceed to Question 2
    }
  } 
  //---------------------
  if (flag ==2 || flag == 1 || flag ==3) {
    if (mouseX>1316 && mouseX < 1366 && mouseY >0 && mouseY <50) {
      flag = 0;
    }//if
    //--------------------
    else {
      // flag = 0;
    }
    //
  }//func
}

void draw_back_button_and_some_text1() {
  fill(0);
  text("some text page1 ", 760, 50);
  draw_zurueck_button();
}

void draw_back_button_and_some_text2() {
  fill(0);
  text("some text page2 ", 760, 50);
  draw_zurueck_button();
}

void draw_back_button_and_some_text3() {
  fill(0);
  text("some text page3 ", 760, 50);
  draw_zurueck_button();
}

void draw_back_button_and_some_text4() {
  fill(0);
  text("some text page4 ", 760, 50);
  draw_zurueck_button();
}

void resultScreen() {
  if ((flag == 1 && correct[index] == 1) || (flag == 2 && correct[index] == 2)) {
    // Correct 
    pushStyle();
    background(255);
    fill(0, 255, 0);
    textSize(42);
    text("Richtig!", 600, 150);
    fill(0);
    rect(600, 300, 300, 300);
    textSize(32);
    fill(255);
    text("Nächste", 700, 400);
    text("Aussage->", 700, 450);

    draw_zurueck_button();

    popStyle();
  } else {
    // Wrong 
    pushStyle();
    background(255);
    fill(255, 0, 0);
    text("Falsch!", 600, 150);
    fill(0);
    rect(600, 300, 300, 300);
    textSize(32);
    fill(255);
    text("Nächste", 700, 400);
    text("Aussage->", 700, 450);

    draw_zurueck_button();

    popStyle();
  }
}//

boolean over(int x, int y, int w, int h) {
  return ( mouseX > x & mouseX < x + w &&
    mouseY > y & mouseY < y + h ) ;
}

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [January 25, 2020, 3:16pm UTC](https://discourse.processing.org/t/how-to-do-a-true-or-false-game/15963/23 "2020-01-25T15:16:05Z")

</div>

Yes. What could be the reasons?

What does the error message mean?

---

<div class="post-metadata">

**Author:** ![Ladan](https://avatars.discourse-cdn.com/v4/letter/l/dbc845/32.png) [@Ladan](https://discourse.processing.org/u/Ladan)\
**Post date:** [January 26, 2020, 10:53am UTC](https://discourse.processing.org/t/how-to-do-a-true-or-false-game/15963/24 "2020-01-26T10:53:23Z")

</div>

Didnt i fix it here?

```auto
index++;
    if ( index >= text2.length ) state=7;
    flag=0;

```

```auto
int state = 0;
color green = color(72, 255, 0);
color red = color(255, 17, 0);
color lightblue = color(3, 182, 252);

int flag = 0;

// 3 parallel arrays 

String[] text1 = { 
  "1. Aussage:", 
  "2. Aussage:", 
  "3. Aussage:", 
  "4. Aussage:", 
  "5. Aussage:", 
  "6. Aussage:", 
};

String[] text2 = { 
  "Wir haben einen nicht gelisteten Helfer.", 
  " Wir sind das erste Mal dabei.", 
  "Unser Team besteht nur aus Leuten aus der 7. Klasse.", 
  " Unserer ITler ist der coolste.", 
  "Beim letzten Wettkampf kamen wir in die Top 5.", 
  "Unsere Schule stellt ein anderes Team.", 
};

int[] correct = {
  1, 
  2, 
  2, 
  1, 
  2, 
  1, 
};

// index for all 3 
int index = 0; 

String QUIZ = "Q\nU\nI\nZ\n";

int x1=100, y1=100, w1=250, h1=250; //Button oben links
int x2=1570, y2=100, w2=250, h2=250; //Button oben rechts
int x3=100, y3=750, w3=250, h3=250; //Button unten links
int x4=1570, y4=750, w4=250, h4=250; //Button unten rechts
int x5=80, y5=910, w5=250, h5=100; // Button zurück
int x6=860, y6=0, w6=200, h6=1080; //Button Quiz
int x7=260, y7=290, w7=500, h7=500; //Quiz left Button
int x8=1160, y8=290, w8=500, h8=500; //Quiz right Button

void drawMainButtons() { // _______ stat 0 only
  if ( over(x1, y1, w1, h1) ) stroke(200, 0, 0); 
  else stroke(0);
  rect(x1, y1, w1, h1);
  if ( over(x2, y2, w2, h2) ) stroke(200, 0, 0); 
  else stroke(0);
  rect(x2, y2, w2, h2);
  if ( over(x3, y3, w3, h3) ) stroke(200, 0, 0); 
  else stroke(0);
  rect(x3, y3, w3, h3);
  if ( over(x4, y4, w4, h4) ) stroke(200, 0, 0); 
  else stroke(0);
  rect(x4, y4, w4, h4);
  if ( over(x6, y6, w6, h6) ) stroke(200, 0, 0); 
  else stroke(0);
  rect(x6, y6, w6, h6);
  draw_quiz_text();
}

void draw_zurueck_button() { //_ state 1,2,3
  fill(0, 0, 200);
  if ( over(x5, y5, w5, h5) ) stroke(200, 0, 0); 
  else stroke(0);
  rect(x5, y5, w5, h5);

  fill(184, 18, 18);
  textSize(55);
  stroke(0);
  text("zurück", x5 + 35, y5 + 68);
  textSize(40);
  fill(0, 0, 200);
}

void draw_quiz_text() {

  fill(184, 18, 18);
  textSize(150);
  stroke(0);
  textLeading(250);
  textAlign(CENTER);
  text(QUIZ, x6 + 95, y6 + 220);
  textAlign(LEFT);
  textSize(40);
  fill(0, 0, 200);
}

void actOnFlag() {
  if (flag == 0) {
    // Question 1
    pushStyle();
    background(255);
    fill(255, 0, 0);
    rect (700, 300, 300, 300);
    fill(0, 255, 0);
    rect (300, 300, 300, 300);
    fill(0, 0, 0);
    text(text1[index], 600, 150);
    text(text2[index], 350, 190);
    textSize(32);
    fill(0, 51, 0);
    text("WAHR", 400, 450);
    textSize(32);
    fill( 128, 0, 0);
    text("FALSCH", 800, 450);
    pushStyle();
  } else if (flag == 1 || flag == 2) {  
    //
    resultScreen();
  } else if (flag == 3) {
    background(255);   

    draw_zurueck_button();

    
    flag=0;
    index++;
    if ( index >= text2.length ) state=7;
    flag=0;
  } else {
    background(255);
    textSize(32);
    fill(255, 0, 0);
    text("Error in actOnFlag: "+flag, 600, 150);
  }
}//func 

void setup() {
  fullScreen();
  //size(1920, 1200);
  fill(0, 0, 200);
  strokeWeight(10);
}

void draw() {
  background(68, 235, 7);

  if ( state == 0 ) drawMainButtons(); 

  if ( state == 1 ) draw_back_button_and_some_text1();
  if ( state == 2 ) draw_back_button_and_some_text2();
  if ( state == 3 ) draw_back_button_and_some_text3();
  if ( state == 4 ) draw_back_button_and_some_text4();

  if ( state == 6 ) actOnFlag();
  if ( state == 7 ) {
   
    textSize(32);
    text("Das war's", 600, 150);
    text("Danke für's mitmachen", 600, 200);
    draw_zurueck_button();
    
  }
}

void mousePressed() {
  if ( state == 0 ) {
    if ( over(x1, y1, w1, h1) ) state = 1;
    if ( over(x2, y2, w2, h2) ) state = 2;
    if ( over(x3, y3, w3, h3) ) state = 3;
    if ( over(x4, y4, w4, h4) ) state = 4;
    if ( over(x6, y6, w6, h6) ) state = 6;
  } else {
    if ( over(x5, y5, w5, h5) ) state = 0;
  }
    

  println("MouseX: " + mouseX + " MouseY: " + mouseY + " Flag: " + flag);

  //------------------------
  if (flag == 0) {
    // Question 1
    if (mouseX>300 && mouseX < 600 && mouseY >300 && mouseY <600) {
      flag = 1;
    }
    if (dist(mouseX, mouseY, 849, 450)<125) {
      flag = 2;
    }
  }
  //------------------------
  // Two result screens with a "Next button"
  else if (flag == 1) {
    // Correct 
    if (mouseX>600 && mouseX < 900 && mouseY >300 && mouseY <600) {
      flag = 3; // both proceed to Question 2
    }
  } else if (flag == 2) {
    // Wrong 
    if (mouseX>600 && mouseX < 900 && mouseY >300 && mouseY <600) {
      flag = 3; // both proceed to Question 2
    }
  } 
  //---------------------
  if (flag ==2 || flag == 1 || flag ==3) {
    if (mouseX>1316 && mouseX < 1366 && mouseY >0 && mouseY <50) {
      flag = 0;
    }//if
    //--------------------
    else {
      // flag = 0;
    }
    //
  }//func
}

void draw_back_button_and_some_text1() {
  fill(0);
  text("some text page1 ", 760, 50);
  draw_zurueck_button();
}

void draw_back_button_and_some_text2() {
  fill(0);
  text("some text page2 ", 760, 50);
  draw_zurueck_button();
}

void draw_back_button_and_some_text3() {
  fill(0);
  text("some text page3 ", 760, 50);
  draw_zurueck_button();
}

void draw_back_button_and_some_text4() {
  fill(0);
  text("some text page4 ", 760, 50);
  draw_zurueck_button();
}

void resultScreen() {
  if ((flag == 1 && correct[index] == 1) || (flag == 2 && correct[index] == 2)) {
    // Correct 
    pushStyle();
    background(255);
    fill(0, 255, 0);
    textSize(42);
    text("Richtig!", 600, 150);
    fill(0);
    rect(600, 300, 300, 300);
    textSize(32);
    fill(255);
    text("Nächste", 700, 400);
    text("Aussage->", 700, 450);

    draw_zurueck_button();

    popStyle();
  } else {
    // Wrong 
    pushStyle();
    background(255);
    fill(255, 0, 0);
    text("Falsch!", 600, 150);
    fill(0);
    rect(600, 300, 300, 300);
    textSize(32);
    fill(255);
    text("Nächste", 700, 400);
    text("Aussage->", 700, 450);

    draw_zurueck_button();

    popStyle();
  }
}//

boolean over(int x, int y, int w, int h) {
  return ( mouseX > x & mouseX < x + w &&
    mouseY > y & mouseY < y + h ) ;
}

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [January 26, 2020, 11:52am UTC](https://discourse.processing.org/t/how-to-do-a-true-or-false-game/15963/25 "2020-01-26T11:52:49Z")

</div>

index is the reason.

set index=0; in state 7

---

<div class="post-metadata">

**Author:** ![Ladan](https://avatars.discourse-cdn.com/v4/letter/l/dbc845/32.png) [@Ladan](https://discourse.processing.org/u/Ladan)\
**Post date:** [January 27, 2020, 7:36am UTC](https://discourse.processing.org/t/how-to-do-a-true-or-false-game/15963/26 "2020-01-27T07:36:50Z")

</div>

Oh right thanks 🙂

---

<div class="post-metadata">

**Author:** ![Ladan](https://avatars.discourse-cdn.com/v4/letter/l/dbc845/32.png) [@Ladan](https://discourse.processing.org/u/Ladan)\
**Post date:** [February 5, 2020, 7:12pm UTC](https://discourse.processing.org/t/how-to-do-a-true-or-false-game/15963/27 "2020-02-05T19:12:06Z")

</div>

Everything works, expect for one thing, if i click the quiz button in the middle on the left, the quiz already answers one question ( “falsch”). Do you know why? I didnt code the Quiz, CyberDodo did

```auto
int state = 0;
color green = color(72, 255, 0);
color red = color(255, 17, 0);
color lightblue = color(3, 182, 252);

PImage Team;

int flag = 0;

// 3 parallel arrays 

String[] text1 = { 
  "1. Aussage:", 
  "2. Aussage:", 
  "3. Aussage:", 
  "4. Aussage:", 
  "5. Aussage:", 
  "6. Aussage:", 
};

String[] text2 = { 
  "Wir haben einen nicht gelisteten Helfer.", 
  " Wir sind das erste Mal dabei.", 
  "Unser Team besteht nur aus Leuten aus der 7. Klasse.", 
  " Unserer ITler ist der coolste.", 
  "Beim letzten Wettkampf kamen wir in die Top 5.", 
  "Unsere Schule stellt ein anderes Team.", 
};

int[] correct = {
  1, 
  2, 
  2, 
  1, 
  2, 
  1, 
};

// index for all 3 
int index = 0; 

String QUIZ = "Q\nU\nI\nZ\n";

int x1=100, y1=100, w1=250, h1=250; //Button oben links
int x2=1570, y2=100, w2=250, h2=250; //Button oben rechts
int x3=100, y3=750, w3=250, h3=250; //Button unten links
int x4=1570, y4=750, w4=250, h4=250; //Button unten rechts
int x5=80, y5=910, w5=250, h5=100; // Button zurück
int x6=860, y6=0, w6=200, h6=1080; //Button Quiz
int x7=260, y7=290, w7=500, h7=500; //Quiz left Button
int x8=1160, y8=290, w8=500, h8=500; //Quiz right Button

void drawMainButtons() { // _______ stat 0 only
  if ( over(x1, y1, w1, h1) ) stroke(255, 251, 0); 
  else stroke(0, 0, 200);
  fill(84, 0, 153);
  rect(x1, y1, w1, h1);
  if ( over(x2, y2, w2, h2) ) stroke(255, 251, 0); 
  else stroke(0, 0, 200);
  fill(84, 0, 153);
  rect(x2, y2, w2, h2);
  if ( over(x3, y3, w3, h3) ) stroke(255, 251, 0); 
  else stroke(0, 0, 200);
  fill(84, 0, 153);
  rect(x3, y3, w3, h3);
  if ( over(x4, y4, w4, h4) ) stroke(255, 251, 0); 
  else stroke(0, 0, 200);
  fill(84, 0, 153);
  rect(x4, y4, w4, h4);
  if ( over(x6, y6, w6, h6) ) stroke(255, 251, 0); 
  else stroke(0, 0, 200);
  fill(84, 0, 153);
  rect(x6, y6, w6, h6);
  draw_quiz_text();
}

void draw_zurueck_button() { //_ state 1,2,3
  fill(84, 0, 153);
  if ( over(x5, y5, w5, h5) ) stroke(255, 251, 0); 
  else stroke(0, 0, 200);
  rect(x5, y5, w5, h5);

  fill(255, 251, 0);
  textSize(55);
  stroke(0);
  text("zurück", x5 + 35, y5 + 68);
  textSize(40);
  fill(0, 0, 200);
}

void draw_low_zurueck_button() {
  fill(84, 0, 153);
  if ( over(x5, y5 + 100, w5 - 50, h5 - 50) ) stroke(255, 251, 0); 
  else stroke(0, 0, 200);
  rect(x5, y5 + 100, w5 - 50, h5 - 50);

  fill(255, 251, 0);
  textSize(50);
  stroke(0);
  text("zurück", x5 + 15 , y5 + 140);
  textSize(40);
  fill(0, 0, 200);
}

void draw_quiz_text() {

  fill(255, 251, 0);
  textSize(150);
  stroke(0);
  textLeading(250);
  textAlign(CENTER);
  text(QUIZ, x6 + 95, y6 + 220);
  textAlign(LEFT);
  textSize(40);
  fill(0, 0, 200);
}

void actOnFlag() {
  if (flag == 0) {
    // Question 1
    pushStyle();
    background(255);
    fill(255, 0, 0);
    rect (700, 300, 300, 300);
    fill(0, 255, 0);
    rect (300, 300, 300, 300);
    fill(0, 0, 0);
    text(text1[index], 600, 150);
    text(text2[index], 350, 190);
    textSize(32);
    fill(0, 51, 0);
    text("WAHR", 400, 450);
    textSize(32);
    fill( 128, 0, 0);
    text("FALSCH", 800, 450);
    pushStyle();
  } else if (flag == 1 || flag == 2) {  
    //
    resultScreen();
  } else if (flag == 3) {
    background(255);   

    draw_zurueck_button();

    
    flag=0;
    index++;
    if ( index >= text2.length ) state=7;
    flag=0;
  } else {
    background(255);
    textSize(32);
    fill(255, 0, 0);
    text("Error in actOnFlag: "+flag, 600, 150);
  }
}//func 

void setup() {
  fullScreen();
  //size(1920, 1200);
  fill(0, 0, 200);
  strokeWeight(10);
  Team = loadImage("Team.png");
}

void draw() {
  background(68, 235, 7);

  if ( state == 0 ) drawMainButtons(); 

  if ( state == 1 ) draw_back_button_and_some_text1();
  if ( state == 2 ) draw_back_button_and_some_text2();
  if ( state == 3 ) draw_back_button_and_some_text3();
  if ( state == 4 ) draw_back_button_and_some_text4();

  if ( state == 6 ) actOnFlag();
  if ( state == 7 ) {
   
    textSize(32);
    text("Das war's", 600, 150);
    text("Danke für's mitmachen", 600, 200);
    draw_zurueck_button();
    index = 0;
    
  }
}

void mousePressed() {
  if ( state == 0 ) {
    if ( over(x1, y1, w1, h1) ) state = 1;
    if ( over(x2, y2, w2, h2) ) state = 2;
    if ( over(x3, y3, w3, h3) ) state = 3;
    if ( over(x4, y4, w4, h4) ) state = 4;
    if ( over(x6, y6, w6, h6) ) state = 6;
  } else {
    if ( state != 1 ){
    if ( over(x5, y5, w5, h5) ) state = 0;
    } else {
     
      if ( state == 1 ) {
       
        if( over(x5, y5 + 100, w5 - 50, h5 - 50) ) state = 0;
        
      }
      
    }
    
  }
    

  println("MouseX: " + mouseX + " MouseY: " + mouseY + " Flag: " + flag);

  //------------------------
  if (flag == 0) {
    // Question 1
    if (mouseX>300 && mouseX < 600 && mouseY >300 && mouseY <600) {
      flag = 1;
    }
    if (dist(mouseX, mouseY, 849, 450)<125) {
      flag = 2;
    }
  }
  //------------------------
  // Two result screens with a "Next button"
  else if (flag == 1) {
    // Correct 
    if (mouseX>600 && mouseX < 900 && mouseY >300 && mouseY <600) {
      flag = 3; // both proceed to Question 2
    }
  } else if (flag == 2) {
    // Wrong 
    if (mouseX>600 && mouseX < 900 && mouseY >300 && mouseY <600) {
      flag = 3; // both proceed to Question 2
    }
  } 
  //---------------------
  if (flag ==2 || flag == 1 || flag ==3) {
    if (mouseX>1316 && mouseX < 1366 && mouseY >0 && mouseY <50) {
      flag = 0;
    }//if
    //--------------------
    else {
      // flag = 0;
    }
    //
  }//func
}

void draw_back_button_and_some_text1() {
  background(Team);
  fill(0);
  //text("some text page1 ", 760, 50);
  //draw_zurueck_button();
  draw_low_zurueck_button();
}

void draw_back_button_and_some_text2() {
  fill(0);
  text("some text page2 ", 760, 50);
  draw_zurueck_button();
}

void draw_back_button_and_some_text3() {
  fill(0);
  text("some text page3 ", 760, 50);
  draw_zurueck_button();
}

void draw_back_button_and_some_text4() {
  fill(0);
  text("some text page4 ", 760, 50);
  draw_zurueck_button();
}

void resultScreen() {
  if ((flag == 1 && correct[index] == 1) || (flag == 2 && correct[index] == 2)) {
    // Correct 
    pushStyle();
    background(255);
    fill(0, 255, 0);
    textSize(42);
    text("Richtig!", 600, 150);
    fill(0);
    rect(600, 300, 300, 300);
    textSize(32);
    fill(255);
    text("Nächste", 700, 400);
    text("Aussage->", 700, 450);

    draw_zurueck_button();

    popStyle();
  } else {
    // Wrong 
    pushStyle();
    background(255);
    fill(255, 0, 0);
    text("Falsch!", 600, 150);
    fill(0);
    rect(600, 300, 300, 300);
    textSize(32);
    fill(255);
    text("Nächste", 700, 400);
    text("Aussage->", 700, 450);

    draw_zurueck_button();

    popStyle();
  }
}//

boolean over(int x, int y, int w, int h) {
  return ( mouseX > x & mouseX < x + w &&
    mouseY > y & mouseY < y + h ) ;
}

```

---

<div class="post-metadata">

**Author:** ![Ladan](https://avatars.discourse-cdn.com/v4/letter/l/dbc845/32.png) [@Ladan](https://discourse.processing.org/u/Ladan)\
**Post date:** [February 5, 2020, 7:18pm UTC](https://discourse.processing.org/t/how-to-do-a-true-or-false-game/15963/28 "2020-02-05T19:18:53Z")

</div>

Also, i dont understand the code of the Quiz-Button-Pressing in

```auto
if (flag == 0) {
    // Question 1
    if (mouseX>300 && mouseX < 600 && mouseY >300 && mouseY <600) {
      flag = 1;
    }
    if (dist(mouseX, mouseY, 849, 450)<125) {
      flag = 2;
    }
  }
  //------------------------
  // Two result screens with a "Next button"
  else if (flag == 1) {
    // Correct 
    if (mouseX>600 && mouseX < 900 && mouseY >300 && mouseY <600) {
      flag = 3; // both proceed to Question 2
    }
  } else if (flag == 2) {
    // Wrong 
    if (mouseX>600 && mouseX < 900 && mouseY >300 && mouseY <600) {
      flag = 3; // both proceed to Question 2
    }
  } 
  //---------------------
  if (flag ==2 || flag == 1 || flag ==3) {
    if (mouseX>1316 && mouseX < 1366 && mouseY >0 && mouseY <50) {
      flag = 0;
    }//if
    //--------------------
    else {
      // flag = 0;
    }
    //
  }//func
}

```

mostly the if ( dist …

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [February 6, 2020, 12:04am UTC](https://discourse.processing.org/t/how-to-do-a-true-or-false-game/15963/29 "2020-02-06T00:04:20Z")

</div>

> [@Ladan](#):
>
> mostly the if ( dist …

Look up dist() command in the reference

It’s just checking if the mouse was pressed on or near the button. Think of a round button. Other ways like the classical check against the corners with \> and \< are also possible

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [February 6, 2020, 12:06am UTC](https://discourse.processing.org/t/how-to-do-a-true-or-false-game/15963/30 "2020-02-06T00:06:16Z")

</div>

> [@Ladan](#):
>
> if i click the quiz button in the middle on the left, the quiz already answers one question ( “falsch”)

> [@Ladan](#):
>
> if ( state == 0 )

In draw() and mousePressed() use if…else if… throughout and not only if alone

---

<div class="post-metadata">

**Author:** ![Ladan](https://avatars.discourse-cdn.com/v4/letter/l/dbc845/32.png) [@Ladan](https://discourse.processing.org/u/Ladan)\
**Post date:** [February 6, 2020, 2:43pm UTC](https://discourse.processing.org/t/how-to-do-a-true-or-false-game/15963/31 "2020-02-06T14:43:06Z")

</div>

i tried to fix it, but it didnt work:

```auto
if (flag == 0) {
    if(state == 6){
    // Question 1
    if ( over(600, 500, 300, 300)) {
      flag = 1;
    }
    if ( over(1000, 500, 300, 300)) {
      flag = 2;
    }
    }
  }
  //------------------------
  // Two result screens with a "Next button"
  else if (flag == 1) {
    // Correct 
    if (mouseX>600 && mouseX < 900 && mouseY >300 && mouseY <600) {
      flag = 3; // both proceed to Question 2
    }
  } else if (flag == 2) {
    // Wrong 
    if (mouseX>600 && mouseX < 900 && mouseY >300 && mouseY <600) {
      flag = 3; // both proceed to Question 2
    }
  } 
  //---------------------
  if (flag ==2 || flag == 1 || flag ==3) {
    if (mouseX>1316 && mouseX < 1366 && mouseY >0 && mouseY <50) {
      flag = 0;
    }//if
    //--------------------
    else {
      // flag = 0;
    }
    //
  }//func

```

```auto
int state = 0;
color green = color(72, 255, 0);
color red = color(255, 17, 0);
color lightblue = color(3, 182, 252);

PImage Team;
PImage Sponsoren;
PImage Produktion;
PImage Konstruktion;

int flag = 0;

// 3 parallel arrays 

String[] text1 = { 
  "1. Aussage:", 
  "2. Aussage:", 
  "3. Aussage:", 
  "4. Aussage:", 
  "5. Aussage:", 
  "6. Aussage:", 
};

String[] text2 = { 
  "Wir haben einen nicht gelisteten Helfer.", 
  " Wir sind das erste Mal dabei.", 
  "Unser Team besteht nur aus Leuten aus der 7. Klasse.", 
  " Unserer ITler ist der coolste.", 
  "Beim letzten Wettkampf kamen wir in die Top 5.", 
  "Unsere Schule stellt ein anderes Team.", 
};

int[] correct = {
  1, 
  2, 
  2, 
  1, 
  2, 
  1, 
};

// index for all 3 
int index = 0; 

String QUIZ = "Q\nU\nI\nZ\n";

int x1=100, y1=100, w1=250, h1=250; //Button oben links
int x2=1570, y2=100, w2=250, h2=250; //Button oben rechts
int x3=100, y3=750, w3=250, h3=250; //Button unten links
int x4=1570, y4=750, w4=250, h4=250; //Button unten rechts
int x5=80, y5=910, w5=250, h5=100; // Button zurück
int x6=860, y6=0, w6=200, h6=1080; //Button Quiz
int x7=260, y7=290, w7=500, h7=500; //Quiz left Button
int x8=1160, y8=290, w8=500, h8=500; //Quiz right Button

void drawMainButtons() { // _______ stat 0 only
  if ( over(x1, y1, w1, h1) ) stroke(255, 251, 0); 
  else stroke(0, 0, 200);
  fill(84, 0, 153);
  rect(x1, y1, w1, h1);
  fill(255, 251, 0);
  textSize(50);
  text("Team", 160, 240);
  
  
  if ( over(x2, y2, w2, h2) ) stroke(255, 251, 0); 
  else stroke(0, 0, 200);
  fill(84, 0, 153);
  rect(x2, y2, w2, h2);
  fill(255, 251, 0);
  textSize(37);
  text("Konstruktion", 1580, 240);
  
  
  if ( over(x3, y3, w3, h3) ) stroke(255, 251, 0); 
  else stroke(0, 0, 200);
  fill(84, 0, 153);
  rect(x3, y3, w3, h3);
  fill(255, 251, 0);
  textSize(45);
  text("Produktion", 106, 890);
  
  
  if ( over(x4, y4, w4, h4) ) stroke(255, 251, 0); 
  else stroke(0, 0, 200);
  fill(84, 0, 153);
  rect(x4, y4, w4, h4);
  fill(255, 251, 0);
  textSize(45);
  text("Sponsoren", 1580, 890);
  
  
  if ( over(x6, y6, w6, h6) ) stroke(255, 251, 0); 
  else stroke(0, 0, 200);
  fill(84, 0, 153);
  rect(x6, y6, w6, h6);
  draw_quiz_text();
}

void draw_zurueck_button() { //_ state 1,2,3
  fill(84, 0, 153);
  if ( over(x5, y5, w5, h5) ) stroke(255, 251, 0); 
  else stroke(0, 0, 200);
  rect(x5, y5, w5, h5);

  fill(255, 251, 0);
  textSize(55);
  stroke(0);
  text("zurück", x5 + 35, y5 + 68);
  textSize(40);
  fill(0, 0, 200);
}

void draw_low_zurueck_button() {
  fill(84, 0, 153);
  if ( over(x5, y5 + 100, w5 - 50, h5 - 50) ) stroke(255, 251, 0); 
  else stroke(0, 0, 200);
  rect(x5, y5 + 100, w5 - 50, h5 - 50);

  fill(255, 251, 0);
  textSize(50);
  stroke(0);
  text("zurück", x5 + 15 , y5 + 140);
  textSize(40);
  fill(0, 0, 200);
}

void draw_quiz_text() {

  fill(255, 251, 0);
  textSize(150);
  stroke(0);
  textLeading(250);
  textAlign(CENTER);
  text(QUIZ, x6 + 95, y6 + 220);
  textAlign(LEFT);
  textSize(40);
  fill(0, 0, 200);
}

void actOnFlag() {
  if (flag == 0) {
    // Question 1
    pushStyle();
    background(255);
    fill(255, 0, 0);
    rect (1000, 500, 300, 300);
    fill(0, 255, 0);
    rect (600, 500, 300, 300);
    fill(0, 0, 0);
    text(text1[index], 900, 250);
    text(text2[index], 650, 290);
    textSize(32);
    fill(0, 51, 0);
    text("WAHR", 700, 650);
    textSize(32);
    fill( 128, 0, 0);
    text("FALSCH", 1100, 650);
    pushStyle();
  } else if (flag == 1 || flag == 2) {  
    //
    resultScreen();
  } else if (flag == 3) {
    background(255);   

    draw_zurueck_button();

    
    flag=0;
    index++;
    if ( index >= text2.length ) state=7;
    flag=0;
  } else {
    background(255);
    textSize(32);
    fill(255, 0, 0);
    text("Error in actOnFlag: "+flag, 600, 150);
  }
}//func 

void setup() {
  fullScreen();
  //size(1920, 1200);
  fill(0, 0, 200);
  strokeWeight(10);
  Team = loadImage("Team.png");
  Sponsoren = loadImage("Sponsoren.png");
  Produktion = loadImage("Produktion.png");
  Konstruktion = loadImage("Konstruktion.png");
}

void draw() {
  background(68, 235, 7);

  if ( state == 0 ) drawMainButtons(); 

  if ( state == 1 ) draw_back_button_and_some_text1();
  if ( state == 2 ) draw_back_button_and_some_text2();
  if ( state == 3 ) draw_back_button_and_some_text3();
  if ( state == 4 ) draw_back_button_and_some_text4();

  if ( state == 6 ) actOnFlag();
  if ( state == 7 ) {
   
    textSize(32);
    text("Das wars", 600, 150);
    text("Danke fürs mitmachen", 600, 200);
    draw_zurueck_button();
    index = 0;
    
  }
}

void mousePressed() {
  if ( state == 0 ) {
    if ( over(x1, y1, w1, h1) ) state = 1;
    if ( over(x2, y2, w2, h2) ) state = 2;
    if ( over(x3, y3, w3, h3) ) state = 3;
    if ( over(x4, y4, w4, h4) ) state = 4;
    if ( over(x6, y6, w6, h6) ) state = 6;
  } else {
    if ( state != 1 && state != 2 && state != 3 && state != 4){
    if ( over(x5, y5, w5, h5) ) state = 0;
    } else {

        if( over(x5, y5 + 100, w5 - 50, h5 - 50) ) state = 0;
 
    }
    
  }
    

  println("MouseX: " + mouseX + " MouseY: " + mouseY + " Flag: " + flag);

  //------------------------
  if (flag == 0) {
    if(state == 6){
    // Question 1
    if ( over(600, 500, 300, 300)) {
      flag = 1;
    }
    if ( over(1000, 500, 300, 300)) {
      flag = 2;
    }
    }
  }
  //------------------------
  // Two result screens with a "Next button"
  else if (flag == 1) {
    // Correct 
    if (mouseX>600 && mouseX < 900 && mouseY >300 && mouseY <600) {
      flag = 3; // both proceed to Question 2
    }
  } else if (flag == 2) {
    // Wrong 
    if (mouseX>600 && mouseX < 900 && mouseY >300 && mouseY <600) {
      flag = 3; // both proceed to Question 2
    }
  } 
  //---------------------
  if (flag ==2 || flag == 1 || flag ==3) {
    if (mouseX>1316 && mouseX < 1366 && mouseY >0 && mouseY <50) {
      flag = 0;
    }//if
    //--------------------
    else {
      // flag = 0;
    }
    //
  }//func
  
}

void draw_back_button_and_some_text1() {
  background(Team);
  fill(0);
  //text("some text page1 ", 760, 50);
  //draw_zurueck_button();
  draw_low_zurueck_button();
}

void draw_back_button_and_some_text2() {
  background(Konstruktion);
  fill(0);
  //text("some text page2 ", 760, 50);
  //draw_zurueck_button();
  draw_low_zurueck_button();
}

void draw_back_button_and_some_text3() {
  background(Produktion);
  fill(0);
  //text("some text page3 ", 760, 50);
  //draw_zurueck_button();
  draw_low_zurueck_button();
}

void draw_back_button_and_some_text4() {
  background(Sponsoren);
  fill(0);
  //text("some text page4 ", 760, 50);
  //draw_zurueck_button();
  draw_low_zurueck_button();
}

void resultScreen() {
  if ((flag == 1 && correct[index] == 1) || (flag == 2 && correct[index] == 2)) {
    // Correct 
    pushStyle();
    background(255);
    fill(0, 255, 0);
    textSize(42);
    text("Richtig!", 600, 150);
    fill(0);
    rect(600, 300, 300, 300);
    textSize(32);
    fill(255);
    text("Nächste", 700, 400);
    text("Aussage->", 700, 450);

    draw_zurueck_button();

    popStyle();
  } else {
    // Wrong 
    pushStyle();
    background(255);
    fill(255, 0, 0);
    text("Falsch!", 600, 150);
    fill(0);
    rect(600, 300, 300, 300);
    textSize(32);
    fill(255);
    text("Nächste", 700, 400);
    text("Aussage->", 700, 450);

    draw_zurueck_button();

    popStyle();
  }
}//

boolean over(int x, int y, int w, int h) {
  return ( mouseX > x & mouseX < x + w &&
    mouseY > y & mouseY < y + h ) ;
}

```

---

<div class="post-metadata">

**Author:** ![Ladan](https://avatars.discourse-cdn.com/v4/letter/l/dbc845/32.png) [@Ladan](https://discourse.processing.org/u/Ladan)\
**Post date:** [February 6, 2020, 2:43pm UTC](https://discourse.processing.org/t/how-to-do-a-true-or-false-game/15963/32 "2020-02-06T14:43:41Z")

</div>

can you fix it for me? i need it tomorrow 🙂

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [February 6, 2020, 2:48pm UTC](https://discourse.processing.org/t/how-to-do-a-true-or-false-game/15963/33 "2020-02-06T14:48:10Z")

</div>

No, not at home

Please see in mousePressed use if else if there too

---

<div class="post-metadata">

**Author:** ![Ladan](https://avatars.discourse-cdn.com/v4/letter/l/dbc845/32.png) [@Ladan](https://discourse.processing.org/u/Ladan)\
**Post date:** [February 7, 2020, 7:58am UTC](https://discourse.processing.org/t/how-to-do-a-true-or-false-game/15963/34 "2020-02-07T07:58:07Z")

</div>

I didnt get it to work ☹

```auto
if (flag == 0) {
    
    // Question 1
    if ( over(600, 500, 300, 300)) {
      if( state == 6){
      flag = 1;
      }
    }
    if ( over(1000, 500, 300, 300)) {
      if( state == 6){
      flag = 2;
      }
    } 
  }

```

```auto
int state = 0;
color green = color(72, 255, 0);
color red = color(255, 17, 0);
color lightblue = color(3, 182, 252);

PImage Team;
PImage Sponsoren;
PImage Produktion;
PImage Konstruktion;

int flag = 0;

// 3 parallel arrays 

String[] text1 = { 
  "1. Aussage:", 
  "2. Aussage:", 
  "3. Aussage:", 
  "4. Aussage:", 
  "5. Aussage:", 
  "6. Aussage:", 
};

String[] text2 = { 
  "Wir haben einen nicht gelisteten Helfer.", 
  " Wir sind das erste Mal dabei.", 
  "Unser Team besteht nur aus Leuten aus der 7. Klasse.", 
  " Unserer ITler ist der coolste.", 
  "Beim letzten Wettkampf kamen wir in die Top 5.", 
  "Unsere Schule stellt ein anderes Team.", 
};

int[] correct = {
  1, 
  2, 
  2, 
  1, 
  2, 
  1, 
};

// index for all 3 
int index = 0; 

String QUIZ = "Q\nU\nI\nZ\n";

int x1=100, y1=100, w1=350, h1=350; //Button oben links
int x2=1470, y2=100, w2=350, h2=350; //Button oben rechts
int x3=100, y3=630, w3=350, h3=350; //Button unten links
int x4=1470, y4=630, w4=350, h4=350; //Button unten rechts
int x5=80, y5=910, w5=250, h5=100; // Button zurück
int x6=860, y6=0, w6=200, h6=1080; //Button Quiz
int x7=260, y7=290, w7=500, h7=500; //Quiz left Button
int x8=1160, y8=290, w8=500, h8=500; //Quiz right Button

void drawMainButtons() { // _______ stat 0 only
  if ( over(x1, y1, w1, h1) ) stroke(255, 251, 0); 
  else stroke(0, 0, 200);
  fill(84, 0, 153);
  rect(x1, y1, w1, h1);
  fill(255, 251, 0);
  textSize(45);
  text("Team", 210, 290);
  
  
  if ( over(x2, y2, w2, h2) ) stroke(255, 251, 0); 
  else stroke(0, 0, 200);
  fill(84, 0, 153);
  rect(x2, y2, w2, h2);
  fill(255, 251, 0);
  textSize(45);
  text("Konstruktion", 1510, 280);
  
  
  if ( over(x3, y3, w3, h3) ) stroke(255, 251, 0); 
  else stroke(0, 0, 200);
  fill(84, 0, 153);
  rect(x3, y3, w3, h3);
  fill(255, 251, 0);
  textSize(45);
  text("Produktion", 160, 830);
  
  
  if ( over(x4, y4, w4, h4) ) stroke(255, 251, 0); 
  else stroke(0, 0, 200);
  fill(84, 0, 153);
  rect(x4, y4, w4, h4);
  fill(255, 251, 0);
  textSize(45);
  text("Sponsoren", 1530, 830);
  
  
  if ( over(x6, y6, w6, h6) ) stroke(255, 251, 0); 
  else stroke(0, 0, 200);
  fill(84, 0, 153);
  rect(x6, y6, w6, h6);
  draw_quiz_text();
}

void draw_zurueck_button() { //_ state 1,2,3
  fill(84, 0, 153);
  if ( over(x5, y5, w5, h5) ) stroke(255, 251, 0); 
  else stroke(0, 0, 200);
  rect(x5, y5, w5, h5);

  fill(255, 251, 0);
  textSize(55);
  stroke(0);
  text("zurück", x5 + 35, y5 + 68);
  textSize(40);
  fill(0, 0, 200);
}

void draw_low_zurueck_button() {
  fill(84, 0, 153);
  if ( over(x5, y5 + 100, w5 - 50, h5 - 50) ) stroke(255, 251, 0); 
  else stroke(0, 0, 200);
  rect(x5, y5 + 100, w5 - 50, h5 - 50);

  fill(255, 251, 0);
  textSize(50);
  stroke(0);
  text("zurück", x5 + 15 , y5 + 140);
  textSize(40);
  fill(0, 0, 200);
}

void draw_quiz_text() {

  fill(255, 251, 0);
  textSize(150);
  stroke(0);
  textLeading(250);
  textAlign(CENTER);
  text(QUIZ, x6 + 95, y6 + 220);
  textAlign(LEFT);
  textSize(40);
  fill(0, 0, 200);
}

void actOnFlag() {
  if (flag == 0) {
    // Question 1
    pushStyle();
    background(255);
    fill(255, 0, 0);
    rect (1000, 500, 300, 300);
    fill(0, 255, 0);
    rect (600, 500, 300, 300);
    fill(0, 0, 0);
    text(text1[index], 900, 250);
    text(text2[index], 650, 290);
    textSize(32);
    fill(0, 51, 0);
    text("WAHR", 700, 650);
    textSize(32);
    fill( 128, 0, 0);
    text("FALSCH", 1100, 650);
    pushStyle();
  } else if (flag == 1 || flag == 2) {  
    //
    resultScreen();
  } else if (flag == 3) {
    background(255);   

    draw_zurueck_button();

    
    flag=0;
    index++;
    if ( index >= text2.length ) state=7;
    flag=0;
  } else {
    background(255);
    textSize(32);
    fill(255, 0, 0);
    text("Error in actOnFlag: "+flag, 600, 150);
  }
}//func 

void setup() {
  fullScreen();
  //size(1920, 1200);
  fill(0, 0, 200);
  strokeWeight(10);
  Team = loadImage("Team.png");
  Sponsoren = loadImage("Sponsoren.png");
  Produktion = loadImage("Produktion.png");
  Konstruktion = loadImage("Konstruktion.png");
}

void draw() {
  background(255);

  if ( state == 0 ) drawMainButtons(); 

  if ( state == 1 ) draw_back_button_and_some_text1();
  if ( state == 2 ) draw_back_button_and_some_text2();
  if ( state == 3 ) draw_back_button_and_some_text3();
  if ( state == 4 ) draw_back_button_and_some_text4();

  if ( state == 6 ) actOnFlag();
  if ( state == 7 ) {
   
    textSize(32);
    text("Das wars", 600, 150);
    text("Danke fürs mitmachen", 600, 200);
    draw_zurueck_button();
    index = 0;
    
  }
}

void mousePressed() {
  if ( state == 0 ) {
    if ( over(x1, y1, w1, h1) ) state = 1;
    if ( over(x2, y2, w2, h2) ) state = 2;
    if ( over(x3, y3, w3, h3) ) state = 3;
    if ( over(x4, y4, w4, h4) ) state = 4;
    if ( over(x6, y6, w6, h6) ) state = 6;
  } else {
    if ( state != 1 && state != 2 && state != 3 && state != 4){
    if ( over(x5, y5, w5, h5) ) state = 0;
    } else {

        if( over(x5, y5 + 100, w5 - 50, h5 - 50) ) state = 0;
 
    }
    
  }
    

  println("MouseX: " + mouseX + " MouseY: " + mouseY + " Flag: " + flag + " State: " + state);

  //------------------------
  
  if (flag == 0) {
    
    // Question 1
    if ( over(600, 500, 300, 300)) {
      if( state == 6){
      flag = 1;
      }
    }
    if ( over(1000, 500, 300, 300)) {
      if( state == 6){
      flag = 2;
      }
    } 
  }
  
  //------------------------
  // Two result screens with a "Next button"
  else if (flag == 1) {
    // Correct 
    if (mouseX>600 && mouseX < 900 && mouseY >300 && mouseY <600) {
      flag = 3; // both proceed to Question 2
    }
  } else if (flag == 2) {
    // Wrong 
    if (mouseX>600 && mouseX < 900 && mouseY >300 && mouseY <600) {
      flag = 3; // both proceed to Question 2
    }
  } 
  //---------------------
  if (flag ==2 || flag == 1 || flag ==3) {
    if (mouseX>1316 && mouseX < 1366 && mouseY >0 && mouseY <50) {
      flag = 0;
    }//if
    //--------------------
    else {
      // flag = 0;
    }
    //
  }//func
  
}

void draw_back_button_and_some_text1() {
  background(Team);
  fill(0);
  //text("some text page1 ", 760, 50);
  //draw_zurueck_button();
  draw_low_zurueck_button();
}

void draw_back_button_and_some_text2() {
  background(Konstruktion);
  fill(0);
  //text("some text page2 ", 760, 50);
  //draw_zurueck_button();
  draw_low_zurueck_button();
}

void draw_back_button_and_some_text3() {
  background(Produktion);
  fill(0);
  //text("some text page3 ", 760, 50);
  //draw_zurueck_button();
  draw_low_zurueck_button();
}

void draw_back_button_and_some_text4() {
  background(Sponsoren);
  fill(0);
  //text("some text page4 ", 760, 50);
  //draw_zurueck_button();
  draw_low_zurueck_button();
}

void resultScreen() {
  if ((flag == 1 && correct[index] == 1) || (flag == 2 && correct[index] == 2)) {
    // Correct 
    pushStyle();
    background(255);
    fill(0, 255, 0);
    textSize(42);
    text("Richtig!", 600, 150);
    fill(0);
    rect(600, 300, 300, 300);
    textSize(32);
    fill(255);
    text("Nächste", 700, 400);
    text("Aussage->", 700, 450);

    draw_zurueck_button();

    popStyle();
  } else {
    // Wrong 
    pushStyle();
    background(255);
    fill(255, 0, 0);
    text("Falsch!", 600, 150);
    fill(0);
    rect(600, 300, 300, 300);
    textSize(32);
    fill(255);
    text("Nächste", 700, 400);
    text("Aussage->", 700, 450);

    draw_zurueck_button();

    popStyle();
  }
}//

boolean over(int x, int y, int w, int h) {
  return ( mouseX > x & mouseX < x + w &&
    mouseY > y & mouseY < y + h ) ;
}

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [February 7, 2020, 9:27am UTC](https://discourse.processing.org/t/how-to-do-a-true-or-false-game/15963/35 "2020-02-07T09:27:01Z")

</div>

For example here

if ( over(x1, y1, w1, h1) ) state = 1;  
if ( over(x2, y2, w2, h2) ) state = 2;

if ( over(x1, y1, w1, h1) ) state = 1;  
else if ( over(x2, y2, w2, h2) ) state = 2;

---

<div class="post-metadata">

**Author:** ![Ladan](https://avatars.discourse-cdn.com/v4/letter/l/dbc845/32.png) [@Ladan](https://discourse.processing.org/u/Ladan)\
**Post date:** [February 7, 2020, 8:37pm UTC](https://discourse.processing.org/t/how-to-do-a-true-or-false-game/15963/36 "2020-02-07T20:37:42Z")

</div>

I fixed it by moving the buttons further to the sides and the program is now done 🙂  
Tomorrow is our Competition btw.

```auto
int state = 0;
color green = color(72, 255, 0);
color red = color(255, 17, 0);
color lightblue = color(3, 182, 252);

PImage Team;
PImage Sponsoren;
PImage Produktion;
PImage Konstruktion;

int flag = 0;

String TeamText = "Wir sind ein Team aus 6 Schülern der LFS Oldenburg und nehmen\ndieses Jahr wieder unter dem Namen Flying Eagle an dem Nordmetall Cup teil, dies ist ein Wettbewerb mit mehren Ebenen, der regionalen, der deutschen und der weltweiten Ebene. Unterstützt werden wir von Team Hurracan, unseren Vorgängern, die uns mit Ideen und Rat zur Seite stehen und auf Regionaler sowie auf Deutscher Ebene sehr erfolgreich waren.";

String[] text1 = { 
  "1. Aussage:", 
  "2. Aussage:", 
  "3. Aussage:", 
  "4. Aussage:", 
  "5. Aussage:", 
  "6. Aussage:", 
};

String[] text2 = { 
  " Wir haben einen nicht gelisteten Helfer.", 
  " Wir sind das erste Mal dabei.", 
  "Unser Team besteht nur aus Leuten aus der 7. Klasse.", 
  " Unserer ITler ist der coolste.", 
  "Beim letzten Wettkampf kamen wir in die Top 5.", 
  "Unsere Schule stellt ein anderes Team.", 
};

int[] correct = {
  1, 
  2, 
  2, 
  1, 
  2, 
  1, 
};

int index = 0; 

String QUIZ = "Q\nU\nI\nZ\n";

int x1=100, y1=100, w1=350, h1=350; //Button oben links
int x2=1470, y2=100, w2=350, h2=350; //Button oben rechts
int x3=100, y3=630, w3=350, h3=350; //Button unten links
int x4=1470, y4=630, w4=350, h4=350; //Button unten rechts
int x5=80, y5=910, w5=250, h5=100; // Button zurück
int x6=860, y6=0, w6=200, h6=1080; //Button Quiz
int x7=100, y7=290, w7=500, h7=500; //Quiz left Button
int x8=1320, y8=290, w8=500, h8=500; //Quiz right Button

void drawMainButtons() { // _______ stat 0 only
  if ( over(x1, y1, w1, h1) ) stroke(255, 251, 0); 
  else stroke(0, 0, 200);
  fill(84, 0, 153);
  rect(x1, y1, w1, h1);
  fill(255, 251, 0);
  textSize(45);
  text("Team", 210, 290);

  if ( over(x2, y2, w2, h2) ) stroke(255, 251, 0); 
  else stroke(0, 0, 200);
  fill(84, 0, 153);
  rect(x2, y2, w2, h2);
  fill(255, 251, 0);
  textSize(45);
  text("Konstruktion", 1510, 280);

  if ( over(x3, y3, w3, h3) ) stroke(255, 251, 0); 
  else stroke(0, 0, 200);
  fill(84, 0, 153);
  rect(x3, y3, w3, h3);
  fill(255, 251, 0);
  textSize(45);
  text("Produktion", 160, 830);

  if ( over(x4, y4, w4, h4) ) stroke(255, 251, 0); 
  else stroke(0, 0, 200);
  fill(84, 0, 153);
  rect(x4, y4, w4, h4);
  fill(255, 251, 0);
  textSize(45);
  text("Sponsoren", 1530, 830);

  if ( over(x6, y6, w6, h6) ) stroke(255, 251, 0); 
  else stroke(0, 0, 200);
  fill(84, 0, 153);
  rect(x6, y6, w6, h6);
  draw_quiz_text();
}

void draw_zurueck_button() { //_ state 1,2,3
  fill(84, 0, 153);
  if ( over(x5, y5, w5, h5) ) stroke(255, 251, 0); 
  else stroke(0, 0, 200);
  rect(x5, y5, w5, h5);

  fill(255, 251, 0);
  textSize(55);
  stroke(0);
  text("zurück", x5 + 35, y5 + 68);
  textSize(40);
  fill(0, 0, 200);
}

void draw_low_zurueck_button() {
  fill(84, 0, 153);
  if ( over(x5, y5 + 100, w5 - 50, h5 - 50) ) stroke(255, 251, 0); 
  else stroke(0, 0, 200);
  rect(x5, y5 + 100, w5 - 50, h5 - 50);

  fill(255, 251, 0);
  textSize(50);
  stroke(0);
  text("zurück", x5 + 15, y5 + 140);
  textSize(40);
  fill(0, 0, 200);
}

void draw_quiz_text() {

  fill(255, 251, 0);
  textSize(150);
  stroke(0);
  textLeading(250);
  textAlign(CENTER);
  text(QUIZ, x6 + 95, y6 + 220);
  textAlign(LEFT);
  textSize(40);
  fill(0, 0, 200);
}

void actOnFlag() {
  if (flag == 0) {

    pushStyle();
    background(255);
    fill(255, 0, 0);
    rect (1100, 500, 300, 300);
    fill(0, 255, 0);
    rect (500, 500, 300, 300);
    fill(0, 0, 0);
    text(text1[index], 870, 250);
    text(text2[index], 620, 290);
    textSize(32);
    fill(0, 51, 0);
    text("WAHR", 600, 650);
    textSize(32);
    fill( 128, 0, 0);
    text("FALSCH", 1200, 650);
    pushStyle();
  } else if (flag == 1 || flag == 2) {  

    resultScreen();
  } else if (flag == 3) {
    background(255);   

    draw_zurueck_button();

    flag=0;
    index++;
    if ( index >= text2.length ) state=7;
    flag=0;
  } else {
    background(255);
    textSize(32);
    fill(255, 0, 0);
    text("Error in actOnFlag: "+flag, 600, 150);
  }
}

void setup() {
  fullScreen();
  fill(0, 0, 200);
  strokeWeight(10);
  //Team = loadImage("Team.png");
  Team = loadImage("Team.jpg");
  Sponsoren = loadImage("Sponsoren.png");
  Produktion = loadImage("Produktion.png");
  Konstruktion = loadImage("Konstruktion.png");
}

void draw() {
  background(255);

  if ( state == 0 ) drawMainButtons(); 

  if ( state == 1 ) draw_back_button_and_some_text1();
  if ( state == 2 ) draw_back_button_and_some_text2();
  if ( state == 3 ) draw_back_button_and_some_text3();
  if ( state == 4 ) draw_back_button_and_some_text4();

  if ( state == 6 ) actOnFlag();
  if ( state == 7 ) {

    textSize(32);
    text("Das wars", 600, 150);
    text("Danke fürs mitmachen", 600, 200);
    draw_zurueck_button();
    index = 0;
  }
}

void mousePressed() {
  if ( state == 0 ) {
    if ( over(x1, y1, w1, h1) ) state = 1;
    if ( over(x2, y2, w2, h2) ) state = 2;
    if ( over(x3, y3, w3, h3) ) state = 3;
    if ( over(x4, y4, w4, h4) ) state = 4;
    if ( over(x6, y6, w6, h6) ) state = 6;
  } else {
    if ( state != 1 && state != 2 && state != 3 && state != 4) {
      if ( over(x5, y5, w5, h5) ) state = 0;
    } else {

      if ( over(x5, y5 + 100, w5 - 50, h5 - 50) ) state = 0;
    }
  }

  println("MouseX: " + mouseX + " MouseY: " + mouseY + " Flag: " + flag);

  if (flag == 0) {
    if (state == 6) {

      if ( over(500, 500, 300, 300)) {
        flag = 1;
      }
      if ( over(1100, 500, 300, 300)) {
        flag = 2;
      }
    }
  } else if (flag == 1) {
    // Wahr
    if (mouseX>600 && mouseX < 900 && mouseY >300 && mouseY <600) {
      flag = 3;
    }
  } else if (flag == 2) {
    // Falsch
    if (mouseX>600 && mouseX < 900 && mouseY >300 && mouseY <600) {
      flag = 3;
    }
  } 

  if (flag ==2 || flag == 1 || flag ==3) {
    if (mouseX>1316 && mouseX < 1366 && mouseY >0 && mouseY <50) {
      flag = 0;
    } else {
      //flag = 0;
    }
  }
}

void draw_back_button_and_some_text1() {
  background(Team);
  fill(0);

  text(TeamText, 50, 50, 1300, 450);

  draw_low_zurueck_button();
}

void draw_back_button_and_some_text2() {
  background(Konstruktion);
  fill(0);
  draw_low_zurueck_button();
}

void draw_back_button_and_some_text3() {
  background(Produktion);
  fill(0);
  draw_low_zurueck_button();
}

void draw_back_button_and_some_text4() {
  background(Sponsoren);
  fill(0);
  draw_low_zurueck_button();
}

void resultScreen() {
  if ((flag == 1 && correct[index] == 1) || (flag == 2 && correct[index] == 2)) {
    // Correct 
    pushStyle();
    background(255);
    fill(0, 255, 0);
    textSize(42);
    text("Richtig!", 600, 150);
    fill(0);
    rect(600, 300, 300, 300);
    textSize(32);
    fill(255);
    text("Nächste", 700, 400);
    text("Aussage->", 700, 450);

    draw_zurueck_button();

    popStyle();
  } else {
    // Wahr
    pushStyle();
    background(255);
    fill(255, 0, 0);
    text("Falsch!", 600, 150);
    fill(0);
    rect(600, 300, 300, 300);
    textSize(32);
    fill(255);
    text("Nächste", 700, 400);
    text("Aussage->", 700, 450);

    draw_zurueck_button();

    popStyle();
  }
}

boolean over(int x, int y, int w, int h) {
  return ( mouseX > x & mouseX < x + w &&
    mouseY > y & mouseY < y + h ) ;
}
//By Daniel & Dodo (+Chrisir xD)

```

---

<div class="post-metadata">

**Author:** ![Ladan](https://avatars.discourse-cdn.com/v4/letter/l/dbc845/32.png) [@Ladan](https://discourse.processing.org/u/Ladan)\
**Post date:** [February 7, 2020, 8:38pm UTC](https://discourse.processing.org/t/how-to-do-a-true-or-false-game/15963/37 "2020-02-07T20:38:59Z")

</div>

Danke 🙂

[Previous page](https://discourse.processing.org/t/how-to-do-a-true-or-false-game/15963.md?page=1)
