I've been trying to increment the saveStrings function into my code, for instance, if you press r then it saves "red" to a file. It is supposed to do that 32 times in one file, varying from red, blue, yellow and green. What I have now is that it just random appears somewhere in the savefile, just the last button I pressed. It's probably a stupid fix, but I can't figure out what to do.
Thanks in advance.
void keyPressed(){
String[] data = new String[32];
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
data[0] = "rood";
saveStrings("data.txt", data);
i = i + 1;
// Als de 32 items bereikt zijn stoppen
if(i>=Woorden.length) {
//Laad Eindpagina en state naar D (Done)
State = 'D';
}
}
if(key=='b' && State == 'R'){
i = i + 1;
println("B has been pressed");
// Schrijf weg in textbestand dat Blauw is ingedrukt bij stimulus i
data[1] = "blauw";
saveStrings("data.txt", data);
// Als de 32 items bereikt zijn stoppen
if(i>=Woorden.length) {
//Laad Eindpagina en state naar D (Done)
State = 'D';
}
}
if(key=='y' && State == 'R'){
i = i + 1;
println("Y has been pressed");
// Schrijf weg in textbestand dat Geel is ingedrukt bij stimulus i
data[2] = "geel";
saveStrings("data.txt", data);
// Als de 32 items bereikt zijn stoppen
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
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.....
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;
//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'; } } }
For a course in college I have to create the Stroop Task. You see a word and you have to push a button to show in which color the word is presented. I have been trying to find a way to show a word to the screen, but all the things I've tried don't seem to work. I made an array of all the words and the goal is to show one word, the subject person pushes a key for the color and then the next word shows up. At this point I can't even seem to show the first word to the screen and I'm hoping maybe some of you can push me in the right direction.