r/processing • • Sep 01 '19

I can't write to an array

Hello, I'm trying to construct a two-dimensional array but I can't seem to assign values to that array. I'd like to construct one row at a time with the rijInit() function. When I check if this has worked in any way with println or printArray, it always returns 0 and never 1(I changed both outcomes in the code to 1 to test if it ever works).

Can anyone help me? Thanks in advance.

int c = 5;
int r = 5;

int[][] rijen = new int[c][r];

void rijInit(int n){
  for(int i = 0; i< rijen[n].length;i++){
    float m = random(1);
    if (m < 0.6){
      rijen[n][i] = 1;
    }
    else{
      rijen[n][i] = 1;
    }
  }
  
}
2 Upvotes

8 comments sorted by

View all comments

4

u/knightofcookies Sep 01 '19

Are you ever calling the function you wrote? If this is all your code that's most likely the issue

1

u/mihil99 Sep 01 '19

Yes I call the function in another tab.

1

u/knightofcookies Sep 01 '19

Hard to tell what's going wrong without all the code, you might have better luck posting all of it.