On the last flag the text is not visible, why?

I tried to put this text (Das war’s Danke für’s mitmachen) on flag 3 but it did not work, why?

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; 

void setup() {
  size( 1920,1080);
  background(255);
}//func 

void draw() {
  background(255);
  actOnFlag();
}//func 

// -------------------------------------------------

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) {
    pushStyle();    
   fill(0);
    rect(1316, 0, 50, 50);
     textSize(23);
    fill(255);
    text("<-", 1326, 30);    
    textSize(32);
     text("Das war's", 600, 150);
     text("Danke für's mitmachen", 600, 200);
    pushStyle();
    flag=0;
    index++;
  } else {
    background(255);
    textSize(32);
    fill(255, 0, 0);
    text("Error in actOnFlag: "+flag, 600, 150);
  }
}//func 

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);
     fill(0);
    rect(1316, 0, 50, 50);
     textSize(23);
    fill(255);
    text("<-", 1326, 30);
    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);
     fill(0);
    rect(1316, 0, 50, 50);
     textSize(23);
    fill(255);
    text("<-", 1326, 30);
    popStyle();
  }
}//

// -------------------------------------------------

void mousePressed() {
  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 
}
1 Like

The sign ’ is a keyword in Processing, so you have to escape it like this :

String escaping = "So wird\'s gemacht!";

The \ sign has to be used with every character you want to have in a String that is also a keyword. They are :

\.[]{}()<>*+-=!?^$|

Though there are exceptions in some cases.

2 Likes

The arrow on the last flag is there but the text is still not there.
Why?

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; 

void setup() {
  size( 1920, 1080);
  background(255);
}//func 

void draw() {
  background(255);
  actOnFlag();
}//func 

// -------------------------------------------------

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) {
    pushStyle();    
    fill(0);
    rect(1316, 0, 50, 50);
    textSize(23);
    fill(255);
    text("<-", 1326, 30);    
    textSize(32);
    text("Das war/'s", 600, 150);
    text("Danke für/'s mitmachen", 600, 200);
    pushStyle();
    flag=0;
    index++;
  } else {
    background(255);
    textSize(32);
    fill(255, 0, 0);
    text("Error in actOnFlag: "+flag, 600, 150);
  }
}//func 

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);
    fill(0);
    rect(1316, 0, 50, 50);
    textSize(23);
    fill(255);
    text("<-", 1326, 30);
    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);
    fill(0);
    rect(1316, 0, 50, 50);
    textSize(23);
    fill(255);
    text("<-", 1326, 30);
    popStyle();
  }
}//

// -------------------------------------------------

void mousePressed() {
  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
}
1 Like

in line 57 i get a

ArrayIndexOutOfBoundsException: 6

and that is correct as your arrays go 0…5 only


also in this
actOnFlag()
use push double but no pop.


a thousand people browsing this forum
what they think when they read your title?
please change that to something what your question is about

1 Like

but im only reading 0…5 right?

a few small errors.

4 is the situation with “Das war’s”



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; 

void setup() {
  size( 1920, 1080);
  background(255);
  if (text1.length!=text2.length||text2.length!=correct.length) {
    println("Keine gleiche Länge");
    exit();
  }
}//func 

void draw() {
  background(255);
  actOnFlag();
}//func 

// -------------------------------------------------

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);
    popStyle();
  } else if (flag == 1 || flag == 2) {  
    //
    resultScreen();
  } else if (flag == 3) {
    // go on to next question 
    flag=0;
    index++;
    if (index>=text1.length) {
      // -> END 
      index=0;
      flag=4;
    }
    //
  } else if (flag==4) {
    // END 
    pushStyle();    
    fill(0);
    rect(1316, 0, 50, 50);
    textSize(23);
    fill(255);
    text("<-", 1326, 30);    
    textSize(32);
    fill(0); 
    text("Das war's.", 600, 150);
    text("Danke für's mitmachen!", 600, 200);
    popStyle();
  } else {
    background(255);
    textSize(32);
    fill(255, 0, 0);
    text("Error in actOnFlag: Unknown flag "
      +flag, 600, 150);
  }
}//func 

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);
    fill(0);
    rect(1316, 0, 50, 50);
    textSize(23);
    fill(255);
    text("<-", 1326, 30);
    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);
    fill(0);
    rect(1316, 0, 50, 50);
    textSize(23);
    fill(255);
    text("<-", 1326, 30);
    popStyle();
  }
}//

// -------------------------------------------------

void mousePressed() {
  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
    }
  } 
  //---------------------
  // BACK Button 
  if (flag == 2 || flag == 1 || flag == 3 || flag == 4) {
    if (mouseX>1316 && mouseX < 1366 && mouseY >0 && mouseY <50) {
      flag = 0;
    }//if
    //--------------------
    else {
      // flag = 0;
    }
    //
  }
}//func
1 Like