For a start I'd suggest you use mouseReleased() instead of pressed, since the latter repeats for as long as the mouse is held - i.e. it will pretty much always get called several times on any given 'single' press. Next, you need to check that the value of count doesn't reach or exceed the length of the array or you'll get the NPE. That's just a matter of wrapping count++ in a condition: if it's equal or greater than the array length set it back to zero ;)
As I wrote very recently, you made a very common error. Not sure why this error comes up so often... I suppose we should have a warning when a local variable shadows a global one (Alex in your case). Actually, IDEs like Eclipse do the warning, at least. In short, don't re-declare Alex in setup(): don't put the type in the line initializing it.
Yeah, I know both of those points (but thanks for mentioning them!) I need to use mousePressed() in this case, and I am wrapping the count. The code I posted was an extract from a larger project, just trying to figure out the problem in a test case, and I didn't bother to include that. But thanks.
Are you saying that I should declare the length of the PImage Array outside of setup() and then the elements in setup() ??
I always saw in examples to put them right after each other... thanks.
You can initialize the array's dimension either in the declaration (outside of setup()) or inside setup(), both are correct. There is not always a "proper way" (in the sense of unique), but there are several improper ways, alas... The initialization of the content of the array is better done (here, it is even mandatory) in setup(), though, as it is only then that the path to the data folder is known.
Leave a comment on PhiLho's reply
Change topic type
Link this topic
Provide the permalink of a topic that is related to this topic