samedi 7 août 2021

How to make an if when button is clicked, how does it know whats selected?

  void draw() {
    image(mImage, posX, posY); //shows all images
     
     if(isClicked) {
  
     //--------check if player selected the right image-------
        if(mImage == imageTrue[0] || mImage == imageTrue[1]
        || mImage == imageTrue[2] || mImage == imageTrue[3]
        || mImage == imageTrue[4] || mImage == imageTrue[5]) {
          print("You found the right image!");
        }
        else {
          print("wrong!");
        }
     }
        //------------------------------
     if(isClicked && mImage != buttom) { //dont mark the buttom
      image(selected, posX, posY, width, height); //mark the selected pic. (selected is a 
                                                   empty green square image, so its shown whats 
                                                   selected)
     }
  }

This is in processing

The player is shown 6 different images, but there is only one true image that he needs to selected. When selected its marked green and then player needs to click on the buttom so submit. Then the if should check if the player selected the true picture or wrong.

The problem: when right images are selected, the console say its a wrong image, because it only check what the players clicks right now. Button is not a true image so the "if" says its wrong.

Question: How can I make an if that it should not check whats clicked right now, it should check whats selected and then check if the picture on what player selected is true or not. How can I solve this in code?

Note: selected is an image that will be placed over the selected picture green empty square, so player can see its selected. the imageTrue is an Array [ ]

Aucun commentaire:

Enregistrer un commentaire