getcell() returns null and I don't know why ... :(

Julien Bayle's icon

Can someone help me with this piece of code I just wrote ...?

p_array is null line 25

This is the line of the if()

I even filled (dumbly) the p_array slots... but no way.

autowatch = 1;
outlets = 2;

var w = 15;

var outmatrix = new JitterMatrix(3,"float32",w,1);
outmatrix.setall(0);

var scalematrix = new JitterMatrix(3,"float32",w,1);
scalematrix.setall(1.);
outlet(1,"jit_matrix",scalematrix.name);

var p_array = new Array(3);
p_array[0] = 0;
p_array[1] = 0;
p_array[2] = 0;

function bang()
{
    for (var i = 0 ; i < w ; i++)
    {
            p_array = outmatrix.getcell(i);

            if (p_array[0] < 20) p_array[0] += Math.random();
            else p_array[0] = 0;

            outmatrix.setcell3d(i,p_array[0],p_array[1],p_array[2]);
    }

    outlet(0,"jit_matrix",outmatrix.name);
}

Jesse's icon

I don't get any errors with your code. I do, however, get a Max window error message from the outlet() call on line 11:

js: bad outlet index 1 [test]

This is because your outlet doesn't yet exist. You should call it in one of your functions to be sure that the object is constructed properly. I believe the loadbang() function executes automatically if you define it. Outlet() calls are safe there.

touk's icon

No errors for your array assignement...
for your setting method of matrix, you declare variable "outmatrix" as a 2D BUT you call method setcell3D, try "outmatrix.setcell2d([i,0],p_array)" to set your datas

Julien Bayle's icon

omg, I don't have any error now.

right for the 2d/3d
I'm in 3 coordinates so 3d works right!