Im trying to create a program where a random letter appears on the screen and the user has to type it to gain 1 point and if they type it within a time frame they get bonus points (I haven’t wrote the point system yet because my current code in not working). The letters in my code fill up the canvas constantly instead of only appearing once.
void setup(){
size(500,500);
}
void draw(){
background(255);
String[] letter = { "A", "B", "C", "D" };
int index = int(random(letter.length));
textSize(25);
fill(100,0,0);
text((letter[index]),200,200);
}
Could you please edit your post and format the code? You can press the button that looks like < /> (Preformatted text) and place your Processing code in there. The outcome should look similar to this:
void setup() {
size(500, 500);
}
void draw() {
// rest of your code
}
You have to take in account that void draw() works like a constant loop. Once your sketch runs, all the code inside of it gets repeated around 60 times a second (unless specified otherwise or if the sketch is too heavy to run it smoothly). That being said, do you understand why the letter keeps switching constantly?
I think it will be a good exercise for you to figure out the difference between local and global variables. If you make int index a global variable, you could –for now as a first step– use mouseReleased to switch the displayed letter.