OK - I might be a little confused here. Let me see if I can break it down.
My goal is to produce a dozen or so different arrays using a “coord” function.
My understanding is that coord does not “return” anything… i.e., if I have something like the following, nested in my draw() function:
locArray = coord();
It will produce a “cannot convert from void to float[]” error.
So, I’m assuming I need to pass some sort of variable into the coord argument, load it with array values, and then use the variable in the rest of the code body.
The issue then, as @scudly poitns out - is that draw() wipes out the array on each frame. This becomes a problem if I need to have access to the arrays outside of this particular if Block.
Maybe I’m still a little hazy on the scope and function aspects of Processing/Java. Apparently, you can’t even pass the variable into an else statement, as the following produces an “locArr cannot be resolved to a variable” error.
void setup(){
size(640, 480);
background(100, 10, 100);
}
void coord(float [] arr1){
for (int x = 0; x < 20; x++) {
arr1[x] = random(1);
};
};
void draw() {
int amt=100;
if ((frameCount%amt) == 1)
{
float [] locArr = new float[20];
coord(locArr);
amt = int(random(100));
}
else {println(locArr);}
};
My next thought was to wrap it in a for loop. This didn’t work either…
void setup(){
size(640, 480);
background(100, 10, 100);
}
void coord(float [] arr1){
for (int x = 0; x < 20; x++) {
arr1[x] = random(1);
};
};
void draw() {
int amt=100;
for (int n = 0; n < 1; n++) {
float [] locArr = new float[20];
if ((frameCount%amt) == 1)
{
coord(locArr);
amt = int(random(100));
}
else {println(locArr);}
};
};