a mystery text() question RESOLVED
in
Programming Questions
•
6 months ago
i'm writing a program that scours my twitter feed for relevant tweets (which it does just fine). However it's suppose to display the tweets on the screen... which it does kind of.
At the beginning of my program, i define these variables (they aren't the only ones):
The the program runs and every 11 seconds the draw() checks twitter when it calls the function getTweets(), that I wrote. In that function there is a loop that runs, and in that loop is this segment of code:
the first time the code runs oldMsg = "empty" and msg = "what ever the incoming tweet is", so the else portion of the condition runs, EXCEPT that it won't print the text() on the screen, until getTweets() is called again 11 seconds later. When it's called the second time, assuming no new tweets have come in, both oldMsg and msg are the same, because oldMsg was updated the first time the getTweets() function ran. so, println("same message as before. Nothing new");, runs. AND then both of the text()s run (nothing else in the else portion runs, just the text()).
Thoughts on this mystery?
Thanks
At the beginning of my program, i define these variables (they aren't the only ones):
- String user;
- String msg = "empty";
- String oldMsg = "empty";
The the program runs and every 11 seconds the draw() checks twitter when it calls the function getTweets(), that I wrote. In that function there is a loop that runs, and in that loop is this segment of code:
- msg = t.getText(); // the message from twitter
- if(oldMsg.equals(msg))
- {
- println("same message as before. Nothing new");
- }
- else
- {
- println("new message!!!");
- println(msg);
- println(oldMsg);
- background(114455);
- text("What people are saying:", 15, 20);
- text(user + " says " + msg, 15, y);
- }
the first time the code runs oldMsg = "empty" and msg = "what ever the incoming tweet is", so the else portion of the condition runs, EXCEPT that it won't print the text() on the screen, until getTweets() is called again 11 seconds later. When it's called the second time, assuming no new tweets have come in, both oldMsg and msg are the same, because oldMsg was updated the first time the getTweets() function ran. so, println("same message as before. Nothing new");, runs. AND then both of the text()s run (nothing else in the else portion runs, just the text()).
Thoughts on this mystery?
Thanks
1