Array

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

Sorting a structure randomly

biro's picture

Hi Guys! this is my first post. So forgive me if the question could seem stupid

I have a directory scanner that retrieve me the list of movies in a specific folder. I'd like to "randomize the order" of that list, so every time i trig the structure, i can scramble the order.

I've tried with javascript with something like this PHP Code: function (__structure out) main (__structure input){ if(input !=null){ var result=new Object(); result.out=input.sort(function(){return (Math.round(Math.random())-0.5)); return result; } }
but it doesen't work....and i don't know neither how to debug it...

Any solution???

Thanks

Sorting arrays and splitting arrays in Javascript

usefuldesign.au's picture

Javascript help for novice coders like me!

Apart from the fact that the JS patch is temperamental — requiring restarts of QC application when it will not parse good script — I attempted to clear up some of the mysteries I had around working with 2D datasets in Javascript. Standard JS array methods that work for 1D arrays often don't work for more complicated array structures.

This composition has three demo JS patches for:

splitting a set of points into two sets (odds and evens by index), sorting an array of dictionaries by a common dictionary key (a-Z) & concatenating both internally created and inputed structures into one array

All the code is well commented, I hope it can save some of the suffering for others that the JS patch has given me. So let me know if it does and I will have been rewarded for posting it.