I really need help! to make a quiz

I’m brand new to processing, completely new. ‘I’m 15 and learning it in class’ type new. My teacher doesnt know a thing about what im doing, but I want to finish this if possible.
I’m trying to make a quiz, essentially. I have to have 5 questions, and each question has to have at least 3 possible answers.
I have so many issues with this code. I can’t get the third question to even come up, I can’t make the answers to the questions different(currently the answers are all B) and so many more issues.
Here’s the code.

Thanks to anyone who tries to help, and im sorry in advance because im confident this is awful.


void setup() {
  size(700, 700); 
  background(255);
  PFont font1;
  font1 = createFont("ACaslonPro-Regular-48", 23);
   
}

//disclaimer!! bugs!! the yes and no will still work after with other questions.
//you have to right click the window so DO NOT USE RIGHT FOR A CHANGE!!!
//for some reason clicking left twice clears the yes/no. 
//dunno if i can have more than 3 things! maybe instead of binding to click bind to a new key.
 boolean callMethod = true;
void draw() {
 
  fill(255);
  stroke(255);
  rect(1, 1, 50, 700);
  int correctanswers = 0;
  surface.setTitle(mouseX + ", " + mouseY);
  stroke(0);
  fill(0);
  textSize(23);
  if (callMethod){
  text("What is the capital of Alberta?", 56, 58); 
  text("Press a if you think it's Red Deer.", 56, 104);
  text("Press b if you think it's Edmonton.", 56, 152);
  text("Press c if you think it's Sherwood Park.", 56, 200);
  callMethod = false;
  }
  
if (keyPressed) {
   if (key == 'a'){
   wrongAnswer();
   } else if (key == 'b') {
   correctAnswer();  
   } else if (key == 'c') {
   wrongAnswer();
   } else {
    wrongInput(); 
   }

  }
 //answer end
  if (mousePressed && mouseButton == LEFT){
   question2(); 
  
  text("Press a if you think it's K.", 57, 95);
  text("Press b if you think it's Na.", 57, 127);
  text("Press c if you think it's S.", 57, 160);
  }
  if (mousePressed && mouseButton == RIGHT) {
   question3();  
  }
  }
  
  //personal functions
  void question3() {
  if (mousePressed && mouseButton == LEFT) {
    fill(255);
    rect(1, 1, 700, 700);
    fill(0);
    text("Who teaches science 10?", 56, 58);
  }
  
}

 void question2() {
   if (mousePressed && mouseButton == LEFT) {
    
    fill(255);
    rect(1, 1, 700, 700);
    fill(0);
    text("What is the symbol for sodium on the periodic table?", 56, 58);
    }
 
}
 
void wrongAnswer() {
   fill(255);
   stroke(255);
   rect(52, 229, 300, 100);
   fill(0);
   stroke(0);
   text("Wrong! Click to continue.", 59, 250);
}

void wrongInput() {
   fill(255);
   stroke(255);
   rect(52, 229, 300, 100);
   fill(0);
   stroke(0);
   text("Follow the rules!", 59, 250);
}

void correctAnswer () {
  int correctanswers = 0;
   fill(255);
   stroke(255);
   rect(52, 229, 300, 100);
   fill(0);
   stroke(0);
   text("Correct! Click to continue.", 59, 250);
   correctanswers = correctanswers + 1;
}
1 Like

(Try to remove these if’s)
Add another variable ‘questoin_num = 1’ , this variable tracks your current qestion
when the player answered, you switch to another question by adding one to ‘question:num’ use switch statement with this variable, if you can

i understand it might be too much,
but just take a look to see that there are some other possible

  • program structures
  • ways like array…

to do that:
( example)

String[] questions  ={
  "start text", 
  "qa\n[a] bla\n[b] blb\n[c] blc", 
  "qb\n[a]\n[b]\n[c]", 
  "qc\n[a]\n[b]\n[c]", 
  "end"};
String[] goodanswers={
  "n.a.", 
  "a", 
  "c", 
  "b", 
  "n.a."};
int q=0, grade=0, gambler = 0;

void setup() {
  size (500, 500);
  println("mouse click: LEFT: next question, RIGHT: start again");
  println("key: [a],[b], ... as indicated in the questions");
}

void draw() {
  background(200, 200, 0);
  fill(0,200,200); // text color
  textSize(25);
  text(questions[q], 10, 20);
  fill(0,200,0); // text color
  textSize(15);
  if ( grade > 0 ) text("grade: "+grade+" fails: "+gambler, width - 200, height - 20);
}

void mousePressed() {
  if ( mouseButton == LEFT ) q++;
  if ( q > 4 ) exit();
  if ( mouseButton == RIGHT ) q = 0;
}

void keyPressed() {
  //println("key: "+key+" keyCode "+keyCode);
  if ( goodanswers[q].equals(str(key)) ) { 
    println("++ ha, expert");
    grade++;
    q++;
  } else { 
    println("-- bad guess, try again or skip with mouse LEFT click");
    gambler++;
  }
}

i looked up switch and I dont really understand it, but I’ll try to work it in because what it’s supposed to do sounds much more convenient.

Thanks!

Thanks so much. That makes a lot of sense.
I used your code as an example and rewrote what I needed by using it as a reference, so thanks again!!