int flag = 0;
void setup() {
size( 1366, 768);
background(255);
}
void draw() {
if(flag == 0){
push();
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("1. Aussage:", 600,150);
text("Wir haben einen nicht gelisteten Helfer.", 350,190);
textSize(32);
fill(0, 51, 0);
text("WAHR", 400, 450);
textSize(32);
fill( 128, 0, 0);
text("FALSCH", 800, 450);
pop();
} else if (flag == 1) {
push();
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);
pop();
} else if (flag == 2) {
push();
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);
pop();
} else if (flag == 3) {
push();
fill(255, 0, 0);
rect (700, 300, 300, 300);
fill(0, 255, 0);
rect (300, 300, 300, 300);
fill(0, 0, 0);
text("2. Aussage:", 600,150);
text("Wir sind das erste Mal dabei.", 350,190);
textSize(32);
fill(0, 51, 0);
text("WAHR", 400, 450);
textSize(32);
fill( 128, 0, 0);
text("FALSCH", 800, 450);
pop();
}
}
void mousePressed(){
println("MouseX: " + mouseX + " MouseY: " + mouseY + " Flag: " + flag);
if(flag == 0){
if(mouseX>300 && mouseX < 600 && mouseY >300 && mouseY <600){
flag = 1;
}
if(dist(mouseX,mouseY,50,50)<25){
flag = 2;
}
}
if(flag == 1){
if(mouseX>600 && mouseX < 900 && mouseY >300 && mouseY <600){
flag = 3;
}
} if(flag == 0){
if(mouseX>700 && mouseX < 1000 && mouseY >300 && mouseY <600){
flag = 2;
}
}
if (flag == 2)
if(mouseX>300 && mouseX < 600 && mouseY >300 && mouseY <600){
flag = 3;
}}
fix WHAT exactly?
- you have / draw 4 pages
- and want jump between them by mouse click on hardcoded buttons?
better error description please
Hello
Is this a homework or academic assignment?
Is it a new topic or related to your last topic? They look similar.
A clear statement of the problem helps.
Add some comments to your code.
Consider drawing a âstate diagramâ:
State Diagram
I use state diagrams and flowcharts for my more complex code.
Hint to get you started:
Try putting flag = 0;
at the end of if statements in the main loop; try one at a time and observe.
That is it for nowâŚ
I remarked in his last thread that arrays would be the way to go
But heâs doing a good job!
but even only button variables and a over function would be a big advancement, see
Background(image) not working - #74 by Chrisir ,
here is a working version. There were a lot of small things to fix.
(as I said: Arrays)
Chrisir
int flag = 0;
void setup() {
size( 1366, 768);
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("1. Aussage:", 600, 150);
text("Wir haben einen nicht gelisteten Helfer.", 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) {
// 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);
popStyle();
} else if (flag == 2) {
// 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);
popStyle();
} else if (flag == 3) {
// Question 2
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("2. Aussage:", 600, 150);
text("Wir sind das erste Mal dabei.", 350, 190);
textSize(32);
fill(0, 51, 0);
text("WAHR", 400, 450);
textSize(32);
fill( 128, 0, 0);
text("FALSCH", 800, 450);
popStyle();
} else {
background(255);
fill(255, 0, 0);
text("Else: "+flag, 600, 150);
}
}//func
// -------------------------------------------------
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
}
}
//---------------------
else if (flag == 3) {
// Question 2
if (mouseX>300 && mouseX < 600 && mouseY >300 && mouseY <600) {
flag = 4;
}
if (dist(mouseX, mouseY, 850, 450)<125) {
flag = 5;
}
}//if
//--------------------
else {
// flag = 0;
}
//
}//func
//
here is an array version
int flag = 0;
// 3 parallel arrays
String[] text1 = {
"1. Aussage:",
"2. Aussage:",
"3. Aussage:",
"4. Aussage:"
};
String[] text2 = {
"Wir haben einen nicht gelisteten Helfer.",
"Wir sind das erste Mal dabei.",
"<3>",
"<4>"
};
int[] correct = {
1,
2,
1,
2
};
// index for all 3
int index = 0;
void setup() {
size( 1366, 768);
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);
popStyle();
} else if (flag == 1 || flag == 2) {
//
resultScreen();
} else if (flag == 3) {
// go on
flag=0;
index++;
} else {
background(255);
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);
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);
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
}
}
//---------------------
else if (flag == 3) {
//
}//if
//--------------------
else {
// flag = 0;
}
//
}//func
//
Thanks, this is an much better option.