kyra
YaBB Newbies
Offline
Posts: 6
Help Needed with Delaying
Jan 26th , 2009, 12:10pm
Hello, I'm a newbie in desperate need of help. I built a programme that 'mirrors' the letters on a normal qwerty keyboard. It is an installation where visitors should type on a poiuyt keyboard. They should type various words and if they typed all of them correctly the program rewards them with a: "You taught yourself how to type" I would like to have this line at the screen for about 3 seconds and then the program should return to the beginning. I cannot get this to work. The delay already occurs with the last word (or letter in the easy version of the program) and then it skips the line totally before returning to the beginning. Can somebody please help me with this? I've been at it for quite a while now and my presentation is only one week ahead, so I'm getting worried. Below you'll find my code. I'll be eternally grateful, kYra code: char [] correct = { 'q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z', 'x','c','v','b','n','m'}; char [] reversed = { 'p','o','i','u','y','t','r','e','w','q','l','k','j','h','g','f','d','s','a','m', 'n','b','v','c','x','z'}; // I would like to have the visitor type words but to // make the program easier to work in, i use only letters // and will change the array when it is completely working // the letters p, d, e are on a 'normal' // keyboard q, j , i String [] words = {"p", "d", "e"}; // String [] words = {"arbitrary", "control", "adapting", "typing", "mistake", "culture", "form", ""}; PFont font; String letters = ""; int counter; int cursorBlinkDelay = 20; float y; int a; void setup() { size(1440, 900); font = loadFont("APCCourier-Bold-48.vlw"); textFont(font); stroke(0); fill(0); } void draw() { background(255); text(words[a], 0,height/4); int lY = height/2; line(0,lY, width, lY); line(0,lY+2, width, lY+2); line(0,lY+4, width, lY+4); y = 0.75 * height; float cursorPosition = textWidth(letters); if (counter++ > cursorBlinkDelay) text("_", cursorPosition, y); if (counter > 2*cursorBlinkDelay) counter = 0; text(letters, 0, y); if(letters.equals(words[a])) a = a+1; if(a == words.length) { text("You taught yourself how to type!!!", 0,height/4); delay(3000); // The delay seems to be the problem, the programme delays allready // after the last letter is exposed I would like to have the above // text ("You taught...") to be on screen for about a second or 3 // and then the programme should return to the beginning. a = 0; } } void keyPressed() { if (key == BACKSPACE) { // Backspace if (letters.length() > 0) { letters = letters.substring(0, letters.length()-1); } } else if (textWidth(letters+key) < width){ char nieuweLetter = omdraaien(key); letters = letters+nieuweLetter; } } char omdraaien(char letter) { char letterUit = ' '; for(int i=0; i<correct.length; i++) { if(letter == correct[i]) { letterUit = reversed[i]; } } return letterUit; }