Storing cells in y_iterate.
#8

For future reference, there is a way without collection of iterators:
pawn Код:
new
    Matrix[X_SIZE][Y_SIZE],
    Iterator:Matrix<X_SIZE * Y_SIZE>
;

public OnGameModeInit()
{
    //Example cells:
    for(new x = 0; x != 3; ++x) {
        for(new y = 0; y != 3; ++y) {
            Matrix[x][y] = x * y;
            Iter_Add(Matrix, x * Y_SIZE + y);
        }
    }

    //Retrieving random cell:
    new
        rnd = Iter_Random(Matrix),
        x = rnd / Y_SIZE,
        y = rnd % Y_SIZE
    ;
   
    printf("Cell at (%d, %d) value is equal %d", x, y, Matrix[x][y]);

    return 1;
}
Reply


Messages In This Thread
Storing cells in y_iterate. - by Crayder - 09.03.2015, 18:33
Re: Storing cells in y_iterate. - by oliverrud - 09.03.2015, 20:42
Re: Storing cells in y_iterate. - by Misiur - 09.03.2015, 20:44
Re: Storing cells in y_iterate. - by Crayder - 09.03.2015, 21:17
AW: Storing cells in y_iterate. - by Nero_3D - 10.03.2015, 04:06
Re: AW: Storing cells in y_iterate. - by Crayder - 10.03.2015, 04:14
AW: Re: AW: Storing cells in y_iterate. - by Nero_3D - 10.03.2015, 13:18
Re: Storing cells in y_iterate. - by Misiur - 10.03.2015, 14:36
Re: Storing cells in y_iterate. - by Crayder - 10.03.2015, 21:24

Forum Jump:


Users browsing this thread: 1 Guest(s)