We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I have this simple code that does not work in my sketch. I have a function which creates and prints an array of 3 elements..but I don't understand why it will print weird stuff instead of the values stored inside of it
void makeChord(int tuning){
float[] chord = new float[3];
chord[0] = 10;
chord[1] = 11;
chord[2] = 12;
println("CHORD "+chord);
}
will print something like
CHORD [F@704c6d5c
CHORD [F@299fec9d
CHORD [F@42674cc4
CHORD [F@be0f9eb
CHORD [F@436c8512
the function gets callend inside another function that's inside the draw. if I put this code in the draw, it will throw the same result. In a new sketch instead it will work fine. no errors in the console
same result also if I do this way
float[] chord = {10,10,10};
println("CHORD "+chord);
note that I have other arrays in the same sketch and they all work fine) thanks
Answers
Standard Java functionality. If you want to see the elements you have to iterate through the array and print then individually.
that's weird because with my other arrays it works without problems..
like the example in the docs
ok but what's the difference? the 'final' keyword?
In order to println() some array correctly, it needs to go there alone!
We can also use printArray() too: https://Processing.org/reference/printArray_.html
good..thanks!