How do you use a specific element from a returned array that comes from a function?

Hi, I've got a question. I have a custom defined function called Projection, that will return an array with two values. The first value is the X-coordinate and the second value is the Y-coordinate. I want to know how to be able to use the returned X-coordinate in a calculation. Thanks!


  • Show your code

    if the array is called a1 you want to use

    a1[0] + 300

    If you‘d return a PVector it would be pv.x + 300

  • There’s also a new forum

  • Without seeing your code my answer is a little generic

    Also see reference and tutorials on arrays

  • void setup() {
      final int x = randomXY()[0];
      println("x: " + x);
    int[] randomXY() {
      final int x = (int) random(width);
      final int y = (int) random(height);
      return new int[] { x, y };
Sign In or Register to comment.