We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Select Two Buttons at Once
Page Index Toggle Pages: 1
Select Two Buttons at Once (Read 601 times)
Select Two Buttons at Once
Nov 23rd, 2009, 11:44am
 
Hello,

I'm trying to make a message pop up only when two buttons are clicked at a time but the user is able to click all the buttons at once and all the text shows up on top of each other.  How do I make i so the user can only click 2 buttons at once.

Since all buttons are clicked the words just overlap each other.  The background is made up of many images so I can't redraw the background.  What should I do?

Below is my code:

Check check1, check2, check3, check4, check5, check6;
PFont font;
String s;
String s2 = "Christian Scriptures of Love";
String s3 = "Islamic Scripture of Love";
String s4 = "Buddism Scripture of Love";
String s5 = "Juddism Scripture of Love";
String s6 = "Christian Scripture of Hate";
String s7 = "Islamic Scripture of Hate";
String s8 = "Buddism Scripture of Hate";
String s9 = "Juddisim Scripture of Hate";

boolean state_1 = false; //hold value to display one state of the application
boolean state_2 = false; //hold value to display one state of the application

PImage sky2, sand2, water2, rocks2, singlerock;
float fuzzy = 0.0;
color yellow = color(220, 214, 41);
color green = color(110, 164, 32);
color other = color(141,161, 188);
color blue = color (83, 129, 201);
color brown = color (57, 54, 27);



void setup(){
size(504, 660);

 singlerock = loadImage ("singlerock.gif");
 water2 = loadImage ("water2.gif");
 sky2 = loadImage("sky2.gif");
 rocks2 = loadImage("rocks2.gif");
 sand2 = loadImage("sand2.gif");
 
 image(singlerock, 0, -60);
 image(water2, 0, -60);
 image(rocks2, 0, -60);
 image(sand2, 0,-60);
 image(sky2, 0, -60);
 
     
  if (fuzzy < 5.0) {
   fuzzy += 0.15;
  }
 
  tint(blue);
  image(water2, 0, -60);
  filter(BLUR, fuzzy);
 
  tint(brown);
  image(singlerock, 0, -60);

 
  tint(yellow);
  image(sand2, 0,-60);
 
  tint(green);
  image(rocks2, 0, -60);
 

   noTint();
 //tint(other);
   image(sky2,0,-60);

 check1 = new Check(125, 30, 50, color(0));
 check2 = new Check(325, 30, 50, color(0));
 check3 = new Check(75, 500, 50, color(0));
 check4 = new Check(175, 500, 50, color(0));
 check5 = new Check(275, 500, 50, color(0));
 check6 = new Check(375, 500, 50, color(0));
 
 font = loadFont("Serif-25.vlw");
 textFont(font);
 s = "LOVE";
// s2 = "HATE";

}

void draw(){
 
 fill(0);
 text(s, 100, 75, 100, 100);
 //text(s2, 375, 75, 175, 150);
 println(state_1);

 
 check1.display();
 check2.display();
 check3.display();
 check4.display();
 check5.display();
 check6.display();
}

void mousePressed() {
 check1.press(mouseX, mouseY);
 check2.press(mouseX, mouseY);
 check3.press(mouseX, mouseY);
 check4.press(mouseX, mouseY);
 check5.press(mouseX, mouseY);
 check6.press(mouseX, mouseY);
 
 
 
 if(check1.checked == true && check3.checked == true)
 {
   state_1 = true;
   //s = "Christian";
   text(s2, 150, 300, 300, 400);
 
 }
 
 
   if(check1.checked == true && check4.checked == true)
 {
   state_1 = true;
   //s = "Isalmic";
   text(s3,150, 300, 300, 400);
   
   
 }
     if(check1.checked == true && check5.checked == true)
 {
   state_1 = true;
   //s = "Buddism";
   text(s4,150, 300, 300, 400);

     
   
 }
      if(check1.checked == true && check6.checked == true)
 {
   state_1 = true;
   //s = "Juddism";
   text(s5,150, 300, 300, 400);
 }
 
 
   if(check2.checked == true && check3.checked == true)
 {
   state_1 = true;
   //s = "Christian";
  text(s6,150, 300, 300, 400);
 }
 
  if(check2.checked == true && check4.checked == true)
 {
   state_1 = true;
   //s = "Islamic";
    text(s7,150, 300, 300, 400);
 
 }
 
  if(check2.checked == true && check5.checked == true)
 {
   state_1 = true;
   //s = "Buddisim";
    text(s8,150, 300, 300, 400);
 
 }
 
  if(check2.checked == true && check6.checked == true)
 {
   state_1 = true;
   //s = "Juddism";
    text(s9,150, 300, 300, 400);

 }
 

   

}

Thanks!
Re: Select Two Buttons at Once
Reply #1 - Nov 23rd, 2009, 12:50pm
 
I suspect that using else if might help.  That way the first condition that returns true gets displayed and the rest are ignored...  Though of course that does mean you have to decide on an order of priority.  Alternatively you could count the number of keys pressed and only display something if only 2 keys (no less, no more) are held...
Re: Select Two Buttons at Once
Reply #2 - Nov 23rd, 2009, 1:34pm
 
I just tried that and the previous text still appears.
Re: Select Two Buttons at Once
Reply #3 - Nov 23rd, 2009, 2:14pm
 
ju wrote on Nov 23rd, 2009, 11:44am:
Since all buttons are clicked the words just overlap each other.  The background is made up of many images so I can't redraw the background.  What should I do


Ah - didn't really pay attention to that bit.  You are going to have to redraw the background each frame, which means moving the image() calls (but not loadImage) from setup() into draw().
Page Index Toggle Pages: 1