Pro Tip : pass multiple values with Javascript

Posted by DusX on 22 September 2015 | Comments

Tags: , , , , ,

Just a really quick one. We are going to look at how you can save hours patching in Isadora, by designing data structures for your User Actors.
When working in Isadora it is generally best to wrap all functional units into User Actors. This allows great design flexibility and consistency.
However, once you start to duplicate these elements and feed the data from them back and forth to the other functional elements (user actors), you can end up with a mesh of patch cords that fan out all over your screen.
Not only making it harder to view/read, but also taking a lot of time to link each and every output to X number of inputs.

What I have found can really save a ton of time, and your carpal tunnel, is to merge data within a User Actor into a single output, as well as; spread data from a single user input.

How? Its rather easy.
In fact merging the inputs to a single passable string can be done with a single line of code in the Javascript actor.
And, the reverse is done with ~ a dozen.

function main()
	return JSON.stringify(arguments);

This short Javascript function is all you need to take any number of text or numerical inputs and output one packed list of values.

Taking the formatted string provided by the above function and unpacking it into separate values takes a little more effort. 
note: I add an additional value to the beginning of the array, so that the default output of the Javascript actor will give you the number of additional outputs required to output all data from the input.
So if the input contains 4 values, this code will output the number 4 as output1, and you will need to set the number of outputs to 5 (1+4) to see all the input data.

function main()
	var parsed = JSON.parse(arguments[0]);
	var array = [];
    for (elem in parsed ) {
       array.push(parsed [elem]);
	array.unshift(array.length); // make the first output value 
				//a count of additional outputs needed
	return array;

This function looks at the number of inputs and creates an output array of the same length + 1 that communicates the length of the input data.

javascript json stringify unstringify

Something to watch for!

This hung me up for a little while.. I forgot exactly how the Javascript IO mutates. 

  • If you want a 'Text' input, you need to connect a 'Text' output to it (the output of 'Trigger Text' is my go to)
  • If you want 'Text' outputs, you need to connect the output to a 'Text' input (the input of the 'Trigger Text' actor does the trick)

This is less confusing for inputs, but outputs will display a Zero if the data received is 'Text' without the output being mutated to type text.