Using a for loop within keypressed
in
Programming Questions
•
11 months ago
We are programming an experiment for a school project. We have some parts working, but for some reason the words don't go to the next one once you press the G button for green. We couldn't find the mistakes. We were not sure what to do with it, we hope maybe some of you can take a look. Maybe it's a stupid mistake, but we can't figure out a fix for it. If you see anything that is not correct, please tell us.
Thanks a lot!
Jurre & Laura
P.S. Sorry for the big code.....
Thanks a lot!
Jurre & Laura
P.S. Sorry for the big code.....
- char State = 'B';
/*States:
B = Ready to Begin
R = Running
P = Paused
D = Done
*/
//Used for counting, program will change state to "Done" when reaching the end of the Array
int i = 0;
// Stimulus 1 declared
Stimulus Stimulus1;
//Gebruikte Font declaren
PFont f;
//Eerste setup
void setup(){
// Initialize stimulus object
Stimulus1 = new Stimulus();
//Basic setup
size(800,600);
frameRate(60);
background(255);
stroke(0);
smooth();
fill(0);
// Font initializeren.
f = createFont("Arial", 40, true);
textFont(f,30);
text("Press the s-button on the keyboard to start",100,100);
}
void keyPressed(){
if(key=='s'){ //'s' = Startknop
switch(State){
case 'B':
State = 'R';
background(255);
println("Entering state: Running");
break;
case 'R':
State = 'P';
println("Entering state: Paused");
break;
case 'P':
State = 'R';
background(255);
println("Entering state: Running");
break;
}
}
if(key=='r' && State == 'R'){
println("R has been pressed");
// Schrijf weg in textbestand dat Rood is ingedrukt bij stimulus i
for (int i = 0; i<Woorden.length; i++) {
//lines of code to execute here
}
// 25 items stop
if(i>=Woorden.length) {
//Laad Eindpagina en state naar D (Done)
State = 'D';
}
}
if(key=='b' && State == 'R'){
println("B has been pressed");
// Schrijf weg in textbestand dat Blauw is ingedrukt bij stimulus i
for (int i = 0; i<Woorden.length; i++) {
//lines of code to execute here
}
// 25 items stop
if(i>=Woorden.length) {
//Laad Eindpagina en state naar D (Done)
State = 'D';
}
}
if(key=='y' && State == 'R'){
println("Y has been pressed");
// Schrijf weg in textbestand dat Geel is ingedrukt bij stimulus i
for (int i = 0; i<Woorden.length; i++) {
//lines of code to execute here
}
// 25 items stop
if(i>=Woorden.length) {
//Laad Eindpagina en state naar D (Done)
State = 'D';
}
}
if(key=='g' && State == 'R'){
println("G has been pressed");
// Schrijf weg in textbestand dat Groen is ingedrukt bij stimulus i
for (int i = 0; i<Woorden.length; i++) {
//lines of code to execute here
}
// Als de 25 items bereikt zijn stoppen
if(i>=Woorden.length) {
//Load Eindpagina en state to D (Done)
State = 'D';
}
}
}
void draw(){
if(State == 'P'){
background(255);
fill(0);
text("Pauze",200,200);
}
if(State == 'R'){
background(255);
Stimulus1.display(i);
}
if(State == 'D'){
background(255);
Eindpagina();
}
}
- String[] Woorden =
{
"Green",
"Car",
"Red",
"Tree",
"Window",
"Blue",
"Cat",
"Yellow",
"Dog",
"Green",
"Mouse",
"Blue",
"Cloud",
"Red",
"Key",
"Yellow",
"Door",
"Green",
"Yellow",
"Blue",
"Lamp",
"Glass",
"Button",
"Red",
"Blue",
"Coat",
"Red",
"Green",
"Rain",
"Dress",
"Yellow",
"Shoe",
};
- color[] kleuren = {
color(0,255,0), //groen
color(255,0,0), //rood
color(0,0,255), //blauw
color(255,255,0), //geel
color(0,255,0), //groen
color(255,0,0), //rood
color(0,0,255), //blauw
color(255,255,0), //geel
color(0,255,0), //groen
color(255,0,0), //rood
color(0,0,255), //blauw
color(255,255,0), //geel
color(0,255,0), //groen
color(255,0,0), //rood
color(0,0,255), //blauw
color(255,255,0), //geel
color(0,255,0), //groen
color(255,0,0), //rood
color(0,0,255), //blauw
color(255,255,0), //geel
color(0,255,0), //groen
color(255,0,0), //rood
color(0,0,255), //blauw
color(255,255,0), //geel
color(0,255,0), //groen
color(255,0,0), //rood
color(0,0,255), //blauw
color(255,255,0), //geel
color(0,255,0), //groen
color(255,0,0), //rood
color(0,0,255), //blauw
color(255,255,0) //geel
};
- //Define Stimulus
class Stimulus {
int a;
color c;
void display(int a){
fill(kleuren[a]);
//show stroop task
textFont(f, 40);
textAlign(CENTER);
text(Woorden[a],200,200);
}
}
1