Nf() number format decimal places to array using for loop

I’m migrating from p5js to processing and something from p5js that works really well its just getting stuck in processing. I’m trying to:

• Define a PImage array
• Load a set of images that are named 0.jpg ~ 11.jpg
• Use a For Loop together with Nf() to abbreviate the loadImage command by using the [i] with the Nf() formatting to take 0 to 0000.jpg etc.

This works great in p5js. Java is not yet my friend.

Here is my code:

PImage[] frontImgs = new PImage[12];
String[] formatOurJPG;

void setup() {
  size(1024, 600);
  for(int i =0; i < 12; i++) {
    formatOurJPG[i] = (nf(i,3));
    frontImgs[i] = loadImage("front__" + formatOurJPG + ".jpg");
  }
}//end setup

I appreciate your help!

Nevermind! So apparently I fixed it by changing line 2 to this:

String[] formatOurPNG = new String[12];

But OMGosh I seriously don’t understand the annoying syntax of array definition in Java, and why its so hard to write to arrays.

D:

Hello,

I saw another error in your code.

Test code:

Did it work as is with your correction?

:)

Hello @glv thanks for your post. What error did you see? Do you mean it’s called png in the reply and jpg in the OP? Or that the nf is set to 3 digits but I mentioned 4 in the OP?
I corrected for both of those but if you have another error let me know!

Hello

The loop should have:

formatOurJPG[i]

:)