We are about to switch to a new forum software. Until then we have removed the registration on this forum.
(Repost with hopefully correct code paste and the somewhat arcane method of indicating code...)
I'm attempting to use String Lists to create a simple scrolling text display. Below is a test snippet to show the prob I'm having with String Lists. The For Loop moves each line up, starting from the top and moving down. It appears there is a bug or problem with the String List 'get' function. If you break inside the for loop that does the scroll, you see in the variables that 'line' keeps getting a NULL value - and I suspect this is why the scroll doesn't really work.
Are there any known problems with the String lists, or am I just not using it correctly?
Code follows:
String curmsg[]; // Holds current message loaded from data folder
StringList vp; // Will hold each line to be displayed on the view port
String line;
int i, j, k, vpWdoSize = 21;
void setup() {
size(500, 440); // Width, Height; X-coord, Y-coord
vp = new StringList();
setvp();
frameRate(5);
}
void draw() {
background(0);
for ( i=vpWdoSize-1; i<=0; i--) {
vp.set(i, vp.get(i-1)); // EG: Line 19 moves to line 20; then line 18 moves to 19, etc...
text(vp.get(i),30,50);
}
vp.set(0,k++ +" new data");
text(frameCount+" dummy",30,random(30,420));
}
void setvp(){
for (i=0; i<vpWdoSize; i++) {
vp.set(i,"mt-"+i ); // initialize the viewport array
}
k = 0;
Answers
Sorry - I read that you are supposed to 'Copy as HTML' to post in the code - it did look good in the preview - now in the live listing it gets broke.... Why is is so @#_@#@ difficult to post code in a programming forum?????
This forum uses Markdown rather than HTML:
https://forum.Processing.org/two/discussion/8045/how-to-format-code-and-text
https://en.Wikipedia.org/wiki/Markdown
Ok - but struggling enough with Processing - no time to learn Markdown! :-(
I've tried it and still had bad results. Can I delete this post and try over?
We can always edit our own posts! Just re-paste your code according to the "Format Code' article.
Will give it a go. I did use the 'C' button previously, got the two tic marks, pasted my code between, and when I did a preview - it did NOT show any formatting - which is why I tried something else. Will try an edit now...
Pasted first, highlight it and then CTRL+O.
If we hit CTRL+O 1st, we'll only get a pair of apostrophes.
That's only for 1 inline code statement.
Yeah - finally got it - the paste/hightlight/C button sorta threw me... not intuitive but once you know it - pretty easy. Like trying to drive around in Phila, PA!
I particularly don't rely on CTRL+O nor button C.
Instead still in the PDE: CTRL+T, CTRL+A, TAB, TAB, CTRL+C.
Only then CTRL + V here in the forum. :-bd
I don't think there is anything wrong with Lists. You make a mistake in your for-loop. You start with
i
beeing20
and the stop-condition isi<=0
. That is true right from the start, so the code inside of the loop will never be executed.But since we have a list, we can add and remove items from that list, which makes it easy to "scroll" the items. Here is an example:
benja - thanks for catching that error! Also wasn't aware of the .push feature. Figured I had to be doing something dumb.
Neither moi! They still hadn't published those new methods in the reference either:
https://Processing.org/reference/StringList.html
But it's merely an alias for append():
https://Processing.org/reference/StringList_append_.html
https://GitHub.com/processing/processing/blob/master/core/src/processing/data/StringList.java#L164
There's also appendUnique(), but not pushUnique()! :P
https://GitHub.com/processing/processing/blob/master/core/src/processing/data/StringList.java#L318