not more than one word
in
Programming Questions
•
1 years ago
I try to make a program, but now I want that the word that random appear just one time appears.
Now there are a lot of words that appear. I tried to fix it with a boolean but it dont work. :S
- int frames;
- char State;
- int timeToNextw;
- int timeOffset1;
- PFont fontA;
- float hold;
- boolean wordappear;
- void setup() {
- State = 'A';
- size(600, 600);
- background(255);
- frameRate(60);
- hold=millis();
- }
- void draw () {
- if (State == 'A') {
- background(255);
- wordappear = true; // here the boolean but it dont work
- if (wordappear == true) {
- word(); // one random word
- wordappear = false; //word not more than once (doesnt work)
- }
- if(millis()-hold > 900) // to the next state
- {
- State = 'B';
- hold=millis();
- }
- if (State == 'B') {
- background(255);
- println("Hi ");
- }
- }
- }
- void word () {
- float side = random(2) ;
- if (side <= 1) {
- side = 100;
- println( "left");
- }
- else {
- side = 500;
- println( "right");
- }
- fontA = loadFont("Arial-BoldMT-16.vlw");
- textFont(fontA, 16);
- fill (0);
- String[] words = {
- "sit", "question", "save", "bell", "taste", "seven", "one", "boot"
- };
- int index = int(random(words.length));
- println(words[index]); // print one of the six words
- text(words[index], side, 300);
- }
1