the void in "void testArray" is what is returned by the array.
in your case, it should return an int[].. so "int[] testArray"
then, at the bottom of your testArray function, add "return testArray;"
and then you make another function, i.e. sumArray, and use the testArray function in that
Code:
int bg = (int) random (1, 360);
void setup(){
size (200, 180);
colorMode(HSB, 360, 100, 100);
//int bg = (int) random (1, 360);
background(bg, 20, 90);
PFont font;
font = loadFont ("ArialMT-20.vlw");
textFont (font);
noLoop();
}
void draw(){
fill(bg, 10, 90);
rect(80, 22, 100, 100);
fill(360);
sumArray();
fill(0);
line (40, 20, 40, 160);
}
int[] testArray (int length) {
int [] testArray = new int [length];
for (int i = 0; i < testArray.length; i++){
testArray[i] = (int) random (10);
}
return testArray; // i mentioned this line in my comment
}
void sumArray(){
int[] testArray = testArray(5); // and here we use the function, requestion an arraylength of 5
int sum = 0;
int xpos = 20;
int ypos = 40;
int rectYpos = 22;
for (int i = 0; i < testArray.length; i++){
//println (testArray);
sum = sum += testArray[i];
//println (sum);
text (i, xpos, ypos);
text (testArray[i], xpos + 30, ypos);
ypos = ypos + 20;
rect(80, rectYpos, testArray[i]*10, 20);
rectYpos += 20;
}
fill (0);
text (sum, xpos +30 , ypos+5);
}