We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Problem with text display in for() loop.
Page Index Toggle Pages: 1
Problem with text display in for() loop. (Read 753 times)
Problem with text display in for() loop.
Mar 25th, 2010, 7:09pm
 
I'm retreiving tweets from Twitter which I then break up into single words and arrange as an array of strings. I've this loop within the draw loop so that i can see each word drawn on screen individually. YET, when i run the loop, only the final word of the tweet will be drawn...everything else in this loop below works as it should. the text shows up in the print box, but only the final word gets drawn in the display window. anyone seeing what i'm missing?


 for(int i=0; i<((singleWords.length)-1); i++){    
   background(0);
   delay(500);
   text(singleWords[i], 75,75);
   delay(500);
   println(i + ": " + singleWords[i]);
 }
Re: Problem with text display in for() loop.
Reply #1 - Mar 25th, 2010, 7:32pm
 
processing runs the entire loop each time it runs the loop. So the loop will draw the background over the second last bit of text and then prints the last bit of text.
Re: Problem with text display in for() loop.
Reply #2 - Mar 26th, 2010, 1:58am
 
Don't use delay(). I sincerely think this should be removed from the API, or the reference page should insist even more on the culprits of this function (should be used only with noLoop(), I think).

Solution: use draw() as your loop, maintain a counter incremented on each draw() call, and a time counter (based on millis()) to manage the rate of display.
This isn't very intuitive, but there are lot of examples of such design on the forum.
Or just ask here if you are stuck.
Page Index Toggle Pages: 1