String

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

Return Structures from Javascript Patch

bonerton's picture

I'm trying to input a variable length structure of strings into a javascript patch, concatenate it's members into subdivisions of n, and output the new 'compressed' structure, but this javascript isn't returning anything:

function (__structure arrOut) main (__structure arrIn, __number n)
{
   var result = new Object();
   var out = [];
 
   if(!_testMode) {
      for(var i = 0; i < arrIn.length(); i += n) {
         out.push(arrIn.slice(i, i+n).join(" "));
      }
      return out;
   }
 
   result.arrOut = out;
   return result;
}

It's not throwing up any errors. I was getting an "expression arrIn [null] is not an Object" error, until i checked for testMode. Any help would be greatly appreciated. Thanks!

String to integer using javascript

Swiftlikeninja's picture

Okay I ran into an interesting scenario trying to sort through an xml feed. The Structure I have has a number of completes field and Im trying to get a leaderboard set up with the top completes displayed but the feed has the completes as a string and as such the structure sort sorts them alphabetically. Meaning that 10 would actually come before 2 which can cause some major issues in sorting. I found that if I use a number splitter off the complete index and rebuild the structure w/ the kineme structure maker then sorting works but the structure Im using can range to over 400 members so manually doing this is out of the question and i don't think iterator is the answer. Can anyone assist me in a javascript answer on how to change a substructure in an entire structure list from a string to an integer?

Or even simpler, tell me if Im missing something in the structure sort?

Time Duration (Composition by smokris)

Author: smokris
License: MIT
Date: 2010.04.08
Compatibility: 10.5, 10.6
Categories:
Required plugins:
(none)

Given a number of seconds, produces a human-readable string description of the time period.

E.g., converts "5502" into "1 hour, 31 minutes, 42 seconds".

Based on PHP code from http://aidanlister.com/2004/04/making-time-periods-readable/

String Pad (Composition by smokris)

Author: smokris
License: MIT
Date: 2010.04.08
Compatibility: 10.5, 10.6
Categories:
Required plugins:
(none)

Given a string, ensures that the string is at least the specified number of characters. Optionally trims the string, so the result is exactly the specified number of characters.