Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: JavaScript Pre-calculation



hi robert.  i've been messing around w/ js init as well.
after much stabbing in the dark i've found that it's safest to always
use intermediary variables for inputs and outputs which are
initialized when their corresponding array member in inputs[] or
outputs is undefined.  i also discovered that i need to touch the data
on initialization.  I've attached a patch which, i believe, does what
you are looking for.  it is mainly composed of 2 js patches.  one
which generates an array once and one which processes that array, in
this case continuously by converting the array to a string and adding
the patch time.  please let me know if you have any further findings
regarding js in qc.
alex.    

// the array generator /////////////////////////////////////
--------------------------------------------------------------------
/* init */
if (outputs[0] == undefined) {
	var array = new Array("a", "b", "c");
}

/* touch the data... otherwise it is not initialized??? */
var temp = array[0];

/* output */
outputs[0] = array;
--------------------------------------------------------------------

// the array processor ////////////////////////////////////
--------------------------------------------------------------------
/* init */
var array = inputs[0];
if (inputs[0] == undefined) {
	array = new Array(0,0,0);
}

var time = inputs[1];
if (inputs[1] == undefined) {
	time = 0;
}

/* process */
var string = array[0] + ":" + time + "\n" + array[1] + ":" + time +
"\n" + array[2] + ":" + time;

/* output */
outputs[0] = string;
--------------------------------------------------------------------



On 8/1/05, Robert McNally <email@hidden> wrote:
> What is the proper way to run a JavaScript patch a single time when my composition starts up, and make its output (a large array) available to other patches?
> 
> The most obvious way to do this seemed to be to create a JavaScript patch that outputs a constant array (i.e., one that doesn't change over time) and simply tie its output to the input(s) of the other patch (another JavaScript) that needs the pre-calculated array (and whose outputs change over time.) This seemed to work fine (with the array being calculated exactly once) until I closed and re-opened my composition-- upon re-opening, the patch that uses the table seems to not be getting valid data, resulting in no motion in my composition. However, when I make even the tiniest edit to the actual JavaScript code of the patch that uses the table, suddenly things start working. So I presume I'm not doing my hookups correctly.
> 
> Thanks,
> 
> Robert
>  _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Quartzcomposer-dev mailing list      (email@hidden)
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/quartzcomposer-dev/email@hidden
> 
> This email sent to email@hidden
>

Attachment: js array test 04.qtz
Description: application/quartzcomposer

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Quartzcomposer-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/quartzcomposer-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.