Search code examples
return

Send value return value


Oke so I have to work in Processing for my school assignment and I have a question. This is my code:

tempArray.add(new TreeDot(randomBranchDotX(randomX),randomBranchDotY(randomY),strokeThickness));

int randomBranchDotX(int _randomX)
{   
 ArrayList tempArray = (ArrayList) branchList.get(i);
 TreeDot temp = (TreeDot) tempArray.get(tempArray.size() -1);
}

I am returning _randomX but is it als possible to send it so i can use it as the array index and then return _randomX. I hope my question is clear because I had trouble explaining it. Thank you in advance!


Solution

  • You can pass as many parameters/arguments into your function as you like and use them as such:

    int randomBranchDotX(int _randomX, int i)
    {   
      ArrayList tempArray = (ArrayList) branchList.get(i);
      TreeDot temp = (TreeDot) tempArray.get(tempArray.size() -1);
      return _randomX;
    }
    

    Use of this function will require two input paramaters for example:

    randomBranchDotX(randomX, avaluefori)

    Although, based on your example, you're calling randomBranchDotX in a way where the return value isn't utilised....

    EDIT: I wrote it wrong lol, you are using the return value, just that your initial code didnt return a value is what I was meant to say. Sorry for the confusion.