javascript

Comparing two X,Y,Z structures and generating new one with added indexed values from Serial I/O.

mvesga's picture

Hi, I have an string of comma separated values coming from the Serial I/O which correspond to a 16x16 matrix Array. I'm breaking down the string into a Structure with 16 index members every 16 values, on a queue size of 16 (16x16). I'm struggling trying to generate a structure containing the 256 members (I'm only getting a structure of 34 members) from the array which then I would like to include (and match) to it's corresponding ordered position in an indexed X,Y,Z structure. Problem is that I won't always have the same amount of members in my X,Y,Z structure. So I would like to detect how many values are actually active on the 16x16 array and then generate a new structure of 4 members containing the matrix value + the X,Y,Z values for its' corresponding index position. My approach was to compare two sets of X,Y,Z Structures in order to generate a third structure that would be composed of the matching values within the two previously compared structures + the active array values passed through an iterator. Problem is I can't seem to pass on the queued values properly inside iterators; from a 16 sized queued structure of 16 members I'm only getting a structure of 34 members/iterations.

I'm using the following Javascript in order to accomplish this:

function (__structure s1d) main (__structure s2d, __index size, __number len) 
{ 
   var result = new Object();
   var j = 0;
   var f=0;
   q=new Array();
 
   for(var i=0;i<size;i++)   
   {
   f="point00" + i;
   q.push(f); //pass the point names
 
      for(var n=0;n<len;n++)
      {
            j=s2d[i][n];
            q.push(j);
         }
 
      }
 
   result.s1d=q; 
   return result;
 
}

Given my limited javascript knowledge I haven't been able to achieve this. Would be great if anyone could point me in the right direction or know how to solve this. Any help would be highly appreciated! and would definitely earn some good karma points ;)

hopefully simple javascript question

orbi72's picture

Can't seem to get something simple to work with Javascript: I have a structure of numbers which i want to make twice as long and fill it with the same order of initial structure members.

So if arrayIN consists of [0,1,2,3] , I want the arrayOUT to look like this [0,1,2,3,0,1,2,3]. kind a like doubling the length with identical array. I think you can .concat a structure in javascript but it doesn't work with my extremely limited javascript skills

don't laugh, I'am doing something foolish here obviously:) Like not iterating the values in the array or something, but how? Can anyone help me Thank you

javascript:

function (__structure arrOut) main (__structure arrIn) { var result = new Object(); var arrNew = new Array();

if(!_testMode) { arrNew.concat(arrIn,arrIn); }

result.arrOut = arrNew; return result; }

Help! javascript generated structure: too many members/array to the queue

jacopoB's picture

I've never worked with javascript but i've managed to create a structure, the problem is that i dont know how to dequeue the values. (I want to keep only the newest values 20-40 per points {x,y,z})

Anyone can help?

_Queue = []

function (__structure Queue) main (__number inputNumber[12]) { var result = new Object(); _Queue.push([inputNumber[0],inputNumber[1],inputNumber[2]]) _Queue.push([inputNumber[3],inputNumber[4],inputNumber[5]]) _Queue.push([inputNumber[6],inputNumber[7],inputNumber[8]]) _Queue.push([inputNumber[9],inputNumber[10],inputNumber[11]]) result.Queue = _Queue; return result; }

Mavericks Javascript port from previous version

Swiftlikeninja's picture

I have a series of javascript patches that i developed on a snow leopard and Mountain Lion machine. I was able to open a composition from the previous version and it would function completely including any javascript patches. If I attempted modify the javascript to encapsulate any text in quotation marks I would receive syntax error; invalid character '\u8216'. Such as calling keys vs index in structures.

This would happen no matter what, even if i just deleted previous quotes just to replace them, suddenly the old code had the same syntax error.

I was able to resolve the issue by putting in a new javascript patch (from mavericks) and copying the code from one of the old patches, now every javascript patch is back to working and I can modify all javascript patches no matter the quartz that created it.

Just posting here for both confirmation to see if anyone else has had this happen to them, and to help anyone who may stumble across this issue as well.

I am currently running quartz composer 4.6 OS 10.9 and created the patches originally on quartz composer 4.0 OS 10.6.8

Javascript Increment Index on event

Swiftlikeninja's picture

I am trying to figure out a way to increment an index of an array based on an event (such as left mouse click over a hit area). The code below sets everything to zero and briefly changes the appropriate index to 1 while the mouse is clicked but changes back to 0 once the mouse is released. What I want to happen is each time the index value is incremented then it stores its current value instead of switching to 0. By the end the array should be mixed numbers. Can anyone provide and assistance?

function (__structure out) main (__structure Pos, __boolean Left,__number X,__number Y,__number W,__number H,__number ShiftX,__number ShiftY)
{
   if (!_testMode) {
   len = Pos.length;
   Hits = new Array()
   for (i=0;i<len;i++){
      Hits[i] = 0
   }
   for (j=0;j<len;j++){
      if (Pos[j][1] >= (X-(W/2)) && Pos[j][1] <= (X +(W/2)) && Pos[j][0] >= (Y-(H/2)) && Pos[j][0] <= (Y +(H/2)) && Left){ 
         Hits[j]++
      }
   }
 
   result=new Object();
   result.out=Hits;
   return result;
   }   
}