Mouse click doesn't change back on time table

I have created a time table everything works, the only problem is when I click my mouse it changes to what I wanted but doesn’t go back. Can any one help. Thanks

PImage chemistry;  // Declare a PImage named chemistry
PImage comsci;  // Declare a PImage named comsci
PImage design;  // Declare a PImage named design
PImage ela;  // Declare a PImage named ela
PImage gym;  // Declare a PImage named gym
PImage math;  // Declare a PImage named math
PImage science;  // Declare a PImage named science
PImage social;  // Declare a PImage named social


String teacher1 = "David Hartley" ; // Declare a String named Teacher1, assigned the value "David Hartley"
String teacher2 = "Devin Guertin" ; // Declare a String named Teacher2, assigned the value "Deving Guertin"
String teacher3 = "Jennifer Woods"; // Declare a String named Teacher3, assigned the value "Jennifer Woods"
String teacher4 = "David Stone"   ; // Declare a String named Teacher4, assigned the value "David Stone"
String teacher5 = "Abdulkadir Abdalla"; // Declare a String named Teacher5, assigned the value "Abdulkadir Abdalla"
String teacher6 = "Jefferson Le"; // Declare a String named Teacher6, assigned the value "Jefferson Le"
String teacher7 = "Feizal Merali"; // Declare a String named Teacher7, assigned the value "Feizal Merali"
String Day =       "Day1"; // Declare a String named Day, assigned the value "Day1"

String course1 = "Chemistry 20" ; // Declare a String named course1, assigned the value "Chemistry 20"
String course2 = "Social Studies" ; // Declare a String named course1, assigned the value "Social Studies"
String course3 = "Physical Education"; // Declare a String named course1, assigned the value "Physical Education"
String course4 = "Design Thinking for Innovation"; // Declare a String named course1, assigned the value "Design Thinking for Innovation"
String course5 = "Computer Science" ; // Declare a String named course1, assigned the value "Computer Science"
String course6 = "Mathematics" ; // Declare a String named course1, assigned the value "Mathematics"
String course7 = "Science" ; // Declare a String named course1, assigned the value "Science"
String course8 = "English Language Arts"; // Declare a String named course1, assigned the value "English Language Arts"

String roomchem= "Room #203"; // Declare a String named roomchem, assigned the value "Room #203"
String roomsocial= "Room #208"; // Declare a String named roomsocial, assigned the value "Room #208"
String roomgym= "Red Gym"; // Declare a String named roomgym, assigned the value "Red Gym"
String roomdesign= "Room #145"; // Declare a String named roomdesign, assigned the value "Room #145"
String roomcomsci= "Room #314"; // Declare a String named roomcomsci, assigned the value "Room #314"
String roommath= "Room #229"; // Declare a String named roommath, assigned the value "Room #229"
String roomscience= "Room #303"; // Declare a String named roomscience, assigned the value "Room #303"
String roomela= "Room #322"; // Declare a String named roomela, assigned the value "Room #322"

int winter= #26619C; // Declare an int named winter, assigned the value #26619C;
int fall=   #c67727; // Declare an int named fall, assigned the value #c67727;

String day1= "Day 1"; // Declare a String named day1, assigned the value "Day 1"
String season1= "Fall"; // Declare a String named season1, assigned the value "Fall"
String season2= "Winter"; // Declare a String named season2, assigned the value "Winter"
void setup() {
  size (800,1000); // Makes the window 800x1000 pixels


chemistry=loadImage("chemistry.jpg"); // When  The Variable "chemistry" is called it loads "chemistry.jpg"
comsci=loadImage("comsci.jpg");  // When  The Variable "comsci" is called it loads "comsci.jpg"
design=loadImage("design.jpg");  // When  The Variable "design" is called it loads "design.jpg"
ela=loadImage("ela.jpg");    // When  The Variable "ela" is called it loads "ela.jpg"
gym=loadImage("gym.jpg");  // When  The Variable "gym" is called it loads "gym.jpg"
math=loadImage("math.jpg");   // When  The Variable "math" is called it loads "math.jpg"
science=loadImage("science.jpg");   // When  The Variable "science" is called it loads "science.jpg"
social=loadImage("social.jpg");   // When  The Variable "social" is called it loads "social.jpg"

}
// draw() loops continuously until you close the sketch window.
void draw() {
 background(fall);
  

  
  // Draws 4 red rectangles who's x any pos is from the center
  rectMode(CORNER);
  fill(255,0,0);
  rect(30,135, 350,350);
  rect(420,135, 350,350);
  rect(30,515, 350,350);
  rect(420,515, 350,350);

// Draws a blue rectangle
fill(0,0,255);
rectMode(CENTER);  
  rect(400, 500, 150,150);
  
  //Writes black text
  fill(#000000);
textSize(20);
text(teacher5, 90, 155);
text(course5, 90, 180);
text("Period 1", 90, 205);
text(roomcomsci, 90, 230);

  //Writes black text
fill(#000000);
textSize(20);
text(teacher6, 475, 155);
text(course8, 475, 180);
text("Period 2", 475, 205);
text(roomela, 475, 230);

  //Writes black text
  fill(#000000);
textSize(20);
text(teacher7, 90, 535);
text(course6, 90, 560);
text("Period 3", 90, 585);
text(roommath, 90, 610); 

  //Writes black text
  fill(#000000);
textSize(20);
text(teacher4, 475, 535);
text(course7, 470, 560);
text("Period 4", 475, 585);
text(roomscience, 475, 610); 


  //Writes black text
textSize(40);
text(day1, 350,510);
 
  //Writes black text
textSize(80);
text("Timetable", 200, 100);

// loads image under the variable comsci
image(comsci, 40,240);

// loads image under the variable ela
image(ela, 460, 240);

// loads image under the variable math
image(math,40, 620);

// loads image under the variable science
image(science,460,620);
   
    //Writes black text
  textSize(20);
text(season1,600, 100);


// Makes balck box that is a button to change the timetable
  fill(0);
  rect(700,40,20,20);
  

}






// if the variable fall= #c67727 then the listed variables will equal a different one otherwise it will revert back to its original
 void mouseClicked() {
  if (fall==#c67727) {
    fall = winter;
   comsci=chemistry;                    
 ela=social;  
 math=gym;  
 science=design;  

teacher5=teacher1;
teacher6=teacher2;
teacher7=teacher3;
teacher4=teacher4;

course5=course1;
course8=course2;
course6=course3;
course7=course4;

roomcomsci=roomchem;
roomela=roomsocial;
roommath=roomgym;
roomscience=roomdesign;

season1=season2;
  } else  {
   
    winter=fall;
    chemistry=comsci;                    
   social=ela;  
 gym=math;  
 design=science;  

teacher1=teacher5;
teacher2=teacher6;
teacher3=teacher7;
teacher4=teacher4;

course1=course5;
course2=course8;
course3=course6;
course4=course7;

roomchem=roomcomsci;
roomsocial=roomela;
roomgym=roommath;
roomdesign=roomcomsci;

}
}
1 Like

please, for testing logic you first need to SEE it
so you might UNDERSTAND it.

i cut it out of your code for you:

int winter= #26619C; // Declare an int named winter, assigned the value #26619C;
int fall=   #c67727; // Declare an int named fall, assigned the value #c67727;

void setup() {
  size (800, 1000); // Makes the window 800x1000 pixels
}

void draw() {
  background(fall);
}

void mouseClicked() {
  if (fall==#c67727) {
    fall = winter;
  } else {
    winter=fall;
  }
}

that might help you solve it.

1 Like

I’m not 100% sure, but is the problem in mouse clicked where the initial mouse click changes fall to winter but since it’s winter clicking it again won’t do anything?

you want select ( possibly more that once ) between 2 colors,
so you should never overwrite their settings.

define one more variable like color bg
and then assign it with fall or winter …

1 Like

I’m sorry but I don’t really understand could you elaborate?

does this code help?

int winter= #26619C;
int fall=   #c67727;

color bg;

void setup() {
  size (500, 500);
  bg = fall;
}

void draw() {
  background(bg);
}

void mousePressed() {
  if ( bg == fall ) bg = winter;
  else              bg = fall;
}

1 Like

Thanks for that solution, I made the adjustment, the colors change back and forth but not the other variables.


/*
Program: Assignment 3 Last Date of this Revision: December 17, 2019
Purpose: To learn how to draw and combine different shapes using Processing
Author: Said Rahmani
School: CHHS
Course: Computer Science 10
*/

PImage chemistry;  // Declare a PImage named chemistry
PImage comsci;  // Declare a PImage named comsci
PImage design;  // Declare a PImage named design
PImage ela;  // Declare a PImage named ela
PImage gym;  // Declare a PImage named gym
PImage math;  // Declare a PImage named math
PImage science;  // Declare a PImage named science
PImage social;  // Declare a PImage named social


String teacher1 = "David Hartley" ; // Declare a String named Teacher1, assigned the value "David Hartley"
String teacher2 = "Devin Guertin" ; // Declare a String named Teacher2, assigned the value "Deving Guertin"
String teacher3 = "Jennifer Woods"; // Declare a String named Teacher3, assigned the value "Jennifer Woods"
String teacher4 = "David Stone"   ; // Declare a String named Teacher4, assigned the value "David Stone"
String teacher5 = "Abdulkadir Abdalla"; // Declare a String named Teacher5, assigned the value "Abdulkadir Abdalla"
String teacher6 = "Jefferson Le"; // Declare a String named Teacher6, assigned the value "Jefferson Le"
String teacher7 = "Feizal Merali"; // Declare a String named Teacher7, assigned the value "Feizal Merali"
String Day =       "Day1"; // Declare a String named Day, assigned the value "Day1"

String course1 = "Chemistry 20" ; // Declare a String named course1, assigned the value "Chemistry 20"
String course2 = "Social Studies" ; // Declare a String named course1, assigned the value "Social Studies"
String course3 = "Physical Education"; // Declare a String named course1, assigned the value "Physical Education"
String course4 = "Design Thinking for Innovation"; // Declare a String named course1, assigned the value "Design Thinking for Innovation"
String course5 = "Computer Science" ; // Declare a String named course1, assigned the value "Computer Science"
String course6 = "Mathematics" ; // Declare a String named course1, assigned the value "Mathematics"
String course7 = "Science" ; // Declare a String named course1, assigned the value "Science"
String course8 = "English Language Arts"; // Declare a String named course1, assigned the value "English Language Arts"

String roomchem= "Room #203"; // Declare a String named roomchem, assigned the value "Room #203"
String roomsocial= "Room #208"; // Declare a String named roomsocial, assigned the value "Room #208"
String roomgym= "Red Gym"; // Declare a String named roomgym, assigned the value "Red Gym"
String roomdesign= "Room #145"; // Declare a String named roomdesign, assigned the value "Room #145"
String roomcomsci= "Room #314"; // Declare a String named roomcomsci, assigned the value "Room #314"
String roommath= "Room #229"; // Declare a String named roommath, assigned the value "Room #229"
String roomscience= "Room #303"; // Declare a String named roomscience, assigned the value "Room #303"
String roomela= "Room #322"; // Declare a String named roomela, assigned the value "Room #322"

int winter= #26619C; // Declare an int named winter, assigned the value #26619C;
int fall=   #c67727; // Declare an int named fall, assigned the value #c67727;

String day1= "Day 1"; // Declare a String named day1, assigned the value "Day 1"
String season1= "Fall"; // Declare a String named season1, assigned the value "Fall"
String season2= "Winter"; // Declare a String named season2, assigned the value "Winter"


color bg;
void setup() {
  size (800,1000); // Makes the window 800x1000 pixels


chemistry=loadImage("chemistry.jpg"); // When  The Variable "chemistry" is called it loads "chemistry.jpg"
comsci=loadImage("comsci.jpg");  // When  The Variable "comsci" is called it loads "comsci.jpg"
design=loadImage("design.jpg");  // When  The Variable "design" is called it loads "design.jpg"
ela=loadImage("ela.jpg");    // When  The Variable "ela" is called it loads "ela.jpg"
gym=loadImage("gym.jpg");  // When  The Variable "gym" is called it loads "gym.jpg"
math=loadImage("math.jpg");   // When  The Variable "math" is called it loads "math.jpg"
science=loadImage("science.jpg");   // When  The Variable "science" is called it loads "science.jpg"
social=loadImage("social.jpg");   // When  The Variable "social" is called it loads "social.jpg"

bg=fall; 
}
// draw() loops continuously until you close the sketch window.
void draw() {
 background(bg);
  

  
  // Draws 4 red rectangles who's x and y pos is from the corner
  rectMode(CORNER);
  fill(255,0,0);
  rect(30,135, 350,350);
  rect(420,135, 350,350);
  rect(30,515, 350,350);
  rect(420,515, 350,350);

// Draws a blue rectangle who's x and y pos is from the center
fill(0,0,255);
rectMode(CENTER);  
  rect(400, 500, 150,150);
  
  //Writes black text
  fill(#000000);
textSize(20);
text(teacher5, 90, 155);
text(course5, 90, 180);
text("Period 1", 90, 205);
text(roomcomsci, 90, 230);

  //Writes black text
fill(#000000);
textSize(20);
text(teacher6, 475, 155);
text(course8, 475, 180);
text("Period 2", 475, 205);
text(roomela, 475, 230);

  //Writes black text
  fill(#000000);
textSize(20);
text(teacher7, 90, 535);
text(course6, 90, 560);
text("Period 3", 90, 585);
text(roommath, 90, 610); 

  //Writes black text
  fill(#000000);
textSize(20);
text(teacher4, 475, 535);
text(course7, 470, 560);
text("Period 4", 475, 585);
text(roomscience, 475, 610); 


  //Writes black text
textSize(40);
text(day1, 350,510);
 
  //Writes black text
textSize(80);
text("Timetable", 200, 100);

// loads image under the variable comsci
image(comsci, 40,240);

// loads image under the variable ela
image(ela, 460, 240);

// loads image under the variable math
image(math,40, 620);

// loads image under the variable science
image(science,460,620);
   
    //Writes black text
  textSize(20);
text(season1,600, 100);



}






// if the variable fall= #c67727 then the listed variables will equal a different one otherwise it will revert back to its original
 void mouseClicked() {
  if (bg==fall) {
    bg = winter;
   comsci=chemistry;                    
 ela=social;  
 math=gym;  
 science=design;  

teacher5=teacher1;
teacher6=teacher2;
teacher7=teacher3;
teacher4=teacher4;

course5=course1;
course8=course2;
course6=course3;
course7=course4;

roomcomsci=roomchem;
roomela=roomsocial;
roommath=roomgym;
roomscience=roomdesign;

season1=season2;
  } else  {
   
    bg=fall;
    chemistry=comsci;                    
   social=ela;  
 gym=math;  
 design=science;  

teacher1=teacher5;
teacher2=teacher6;
teacher3=teacher7;
teacher4=teacher4;

course1=course5;
course2=course8;
course3=course6;
course4=course7;

roomchem=roomcomsci;
roomsocial=roomela;
roomgym=roommath;
roomdesign=roomcomsci;

}
}

when you work Processing IDE ( PDE ) please use /Edit / Autoformat OR [ctrl][t]
your logic is still not readable.

anyhow if the background color change the if () {} else {}
works, the rest must be execute too,
if it makes sense i can not see from here,
why that shuffling of variable anyhow?
looks like the same wrong thinking like with the color? but not sure.

I hope this makes it easier to read. I have everything under the same curly bracket for the else and the reason I shuffled the variables is so that it goes back and forth.

void mouseClicked() {
  if (bg==fall) {
    
bg = winter;

    comsci=chemistry;                    

    ela=social;  

    math=gym;  

    science=design;  



    teacher5=teacher1;

    teacher6=teacher2;

    teacher7=teacher3;

    teacher4=teacher4;


    course5=course1;

    course8=course2;

    course6=course3;

    course7=course4;

    roomcomsci=roomchem;

    roomela=roomsocial;

    roommath=roomgym;

    roomscience=roomdesign;

    season1=season2;
  } else {



    bg=fall;

    chemistry=comsci;                    

    social=ela;  

    gym=math;  

    design=science;  

    teacher1=teacher5;

    teacher2=teacher6;

    teacher3=teacher7;

    teacher4=teacher4;

    course1=course5;

    course2=course8;

    course3=course6;

    course4=course7;


    roomchem=roomcomsci;
    roomsocial=roomela;


    roomgym=roommath;

    roomdesign=roomcomsci;

  }
}

i say use [ctrl][t]


you understand that we can not run your code as we not have the pictures…


if i disable them all,
i can click on the canvas and actually see same as with your first color code,
only the first click works, then all the variable are equalized and next click can not change anything…


so basically you still not understand variables…
and i could not teach you anything
my fault

I used [ctrl][t] in processing and it gave me that. I don’t want the solution handed to me I want to learn, but could you explain further about what equalized means. My assumption is that the first click converts one variable to the other and the converted variable is what I listed under else and I made the statement that the converted variable shall return to its original.

I get it now. I understand what you mean now when I was overwriting the settings. Thanks for the tips

1 Like