JS Javascript structure array object

the way of structures sort in javascript

kzmzk's picture

Does anyone can fix structures including x and y into x structures and y structures only in JS because of use for osc? I tried with structure counts and iterator and structures seemed good but didn't work as osc. I wouldn't change the way of use one constructor so that the way of sort structure would be the best. Thank you.

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

Structure in JS patch not working

usefuldesign.au's picture

Why is it this simple JS code doesn't parse?

function (__structure Points_A) main ()
{
   if (!_testMode)
   {
   var Points = new Array();
   for (i=0; i<2; i++)   
      {
         Points[i] = new Object();
         Points[i]["X"] = .1.;
         Points[i]["Y"] = 0.1;
         Points[i]["Z"] = .3;
      }
   result.Points_A = Points
   }
}

When the very similar but more complex code like this is fine:

var    scale = 0.5
 
function (__number J, __structure Point_Structure, __structure Points_A, __structure Points_B) 
   main (__number segments, __number rotations, __number range)
{
   if (!_testMode)
   {
   var   height = - range;
   var result = new Object();
   var points = new Array();
   rot = 0;
   groove = 3.141592653589793 * 2/3;
   Rstep = rotations * 2*3.141592653589793 / segments;
   Zstep = 2 * range/segments;
   var j = 0;
   for (i=0; i<segments*2; i=i+2) 
      {
         points[i]= new Object();
         points[i]["X"] = Math.sin(rot) * scale;
         points[i]["Z"] = Math.cos(rot) * scale;
         points[i]["Y"] = height;
//         The next line creates an object *AND* populates it with data from I'm not sure where from… Try it! (comment out the 3 lines following it at same time)
         points[i+1]= new Object();
//         These 3 lines can be removed and points[i+1] still gets data put in it… weird
         points[i+1]["X"] = Math.sin(rot+groove) * scale;
         points[i+1]["Z"] = Math.cos(rot+groove) * scale;
         points[i+1]["Y"] = height+0.0;
         j++;
         rot += Rstep;
         height += Zstep;
      }   
   result.J = j
   result.Point_Structure = points;
   return result;
   }
}