Forums > Javascript

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

November 11, 2013 | 1:48 pm

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);
}


November 11, 2013 | 3:16 pm

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.


November 11, 2013 | 4:18 pm

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


November 12, 2013 | 6:51 am

omg, I don’t have any error now.

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


Viewing 4 posts - 1 through 4 (of 4 total)