We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello, currently my code is set up that if you click on the right side there is a counter that will go up for every click. there is a counter on the left as well. however i want a way to save the data. for example i want to be able to ask the user if they are male or female. then from there i want to see how many males clicked on left side of frame, and how many females clicked on right side of the frame.
PImage pink;
PImage blue;
PImage shoe;
int mouseClicksR=0;
int mouseClicksL=0;
int midscreen;
void setup () {
size (800,800);
midscreen=400;
pink= loadImage("shoep.png");
blue= loadImage("shoeb.png");
shoe= loadImage("shoe.png");
textAlign(-20, 500);
textSize(50);
}
void draw () {
background(0);
image(pink, 550,275);
image(blue, -20,255);
image(shoe, 150,150);
textSize(32);
text("Vote for which shoe you see", 150, 75);
text(mouseClicksL+"", 75,500,width,height);
text(mouseClicksR+"", 650,500,width,height);
}
void mousePressed() {
// if (mouseButton == LEFT) { mouseClicksL++; } else { mouseClicksL = 0; }
// if (mouseButton == RIGHT) { mouseClicksR++; } else { mouseClicksR = 0; }
if (mouseX < midscreen) //clicked on left side of screen
mouseClicksL++;
else if (mouseX > midscreen) //clicked on right side of screen
mouseClicksR++;
}
Answers
You might consider using the idea of having STATES in your sketch.
That is, add a number to track what state your sketch is in.
If it is state #0, ask the user for their gender. Remember their answer when they click on an option, and then go to the next state, #1.
If it is state #1, ask the user which shoe they see. Since you recorded their gender in state #0, you can update the appropriate counter variable, and go to the next state, state #2. Also record the current time (value returned by
millis()
), because it will be helpful in the next state...In state #2, display a message thanking the user for their input. Then check if five seconds of being in this state has elapsed (how much will the value
millis()
returns increase by?). If five seconds has elapsed, go back to state #0.In this way, you can control the flow of your sketch, and have different "scenes" displayed based on the current sketch state.
Attempt to write this yourself now, and post your attempt if you need more help.