Populating a 2d Array

Hello all,

im trying to populate a 2d array from code.

I want to fill the first row and when this row is full i want to fill the next row. Filling the first row works fine but on filling the next row it skips (overrides) the first element. What am i doing wrong or more precisely how would i do it correct?

    if(moveCounterX < columnsCounter) {
        array[moveCounterX, moveCounterY, 0] = tmp;
        moveCounterX++;
    }else {
        moveCounterX = 0;
        moveCounterY++;                   
        array[moveCounterX, moveCounterY, 0] = tmp;
    }

Thank you in advance

You have 3 dimensions in your array, not 2.

Anway, with 2d arrays I treat the first dimension as rows, and the second column as columns.

array[row,col] = tmp;
col++;//advance
if(col==numCols)
{
    col = 0;//reset
    row++;//advance
}
1 Like

Hello andymads,

yes you are absolutely right, i had a 3 dimension array in my test, because i copied the wrong one over :slight_smile:

And your code snippet helped me alot to fix my problem. Thousand thanks

Allbest