We are about to switch to a new forum software. Until then we have removed the registration on this forum.
OK so i have spent the beginning of my day messing around with this with only partial success. Kind of embarrassing, seemed like it would be relatively easy. anyway i am just trying to modify an example from the reference section so that i can toggle through the items in a stringlist by pressing a mouse. ultimately i want to midi control sequential video clips but baby steps for now...(and i am guessing i might need some kind of buffer for video clips if i don`t want a delay every time i call a new clip but anyway..)
here is my code so far:
int x = 0;
void setup() {
size(200, 200);
inventory = new StringList();
inventory.append("coffee");
inventory.append("flour");
inventory.append("tea");
println(inventory);
noLoop();
fill(0);
textAlign(CENTER);
}
void draw() {
String item = inventory.get(x);
for (x = 0; x < 3; ) {
if (mousePressed == true) {
x = x+1;
text(item, width/2, height/2);
}
}
}
/*void mousePressed () {
if (x < 3) { x = x + 1;
} else { x = 0;
}
}*/
have managed to crash things by commenting noLoop haha! so can someone please school me??
Answers
Take a step back and read what the code is doing. In your draw() function, you get a String item based on x, which is 0. So item is "coffee". Then you loop 3 times. If the mouse is pressed, you increment x and draw the item. So you draw "coffee" three times for some reason, and at the end x equals 3. Then in the next call to draw(), you try to get the item at index 3 (which is the 4th index), and I would bet your program throws an error.
I assume you just want to increment x whenever you press the mouse. Why did you comment out your mousePressed() function? And what are you trying to do with the for loop that I described above?
Some example of mine: :D
Hi and thanks! Yeah i have only been trying to speak this language for a little over a week so there is usually a big difference between what i want to say and what actually comes out of my mouth. Thankfully it is difficult to accidentally insult anybody with this language :P .
@ kevinworkman, What i thought i was trying to say in the for loop was " starting at zero, and going no higher than 2, increment x" . but i see from your translation that's not what i said haha. I commented the mousepressed function because i didn't want to have to retype it if i decided to go back and mess with it some more, and also evidence to those whore kind enough to help, that i am at least making an effort and not running to the forum every time i get stuck!
@ gotoloop, yes this is exactly what i was trying to do! just saw modulo in a video a couple of days ago but it didn't occur to me. also had no idea there was such a thing as redraw().
Ok thanks!
That modulo trick is kinda semi-advanced! :-\" You can replace that w/ this simpler form:
It's used when automatic draw() is turned off w/ noLoop(). That way, a program becomes input-trigger oriented! \m/
Thanks again!