Forums > Javascript

Connect existing object to scripted one

June 10, 2007 | 5:37 pm

Hello,

I’m trying to connect a existing named (thedata) receive object to a newly by js created unpack object. The script as it is crashes when uncommenting the declaration of "thedata". I just can’t figure out how to address the existing object…

The patch:
max v2;
#N vpatcher 886 146 1486 546;
#P button 72 134 15 0;
#P window setfont "Sans Serif" 9.;
#P newex 72 156 80 196617 js dataToGen.js;
#P newex 201 119 37 196617 r data;
#P objectname thedata;
#P connect 2 0 1 0;
#P pop;

The .js file "dataToGen.js"
inlets = 1;
outlets = 0;

var theunpack;
//var thedata = this.patcher.thedata;

function bang()
{
if( theunpack )
{
this.patcher.remove( theunpack );
}
theunpack = this.patcher.newdefault( 200, 200, ‘unpack’, 0, 0);
this.patcher.connect( thedata, 0, theunpack, 0 );
}

Any help is appreciated!
Frans-Jan


June 10, 2007 | 5:46 pm

On 10 juin 07, at 19:37, Frans-Jan Wind wrote:

> function bang()
> {
> if( theunpack )
> {
> this.patcher.remove( theunpack );
> }
> theunpack = this.patcher.newdefault( 200, 200, ‘unpack’, 0, 0);
> this.patcher.connect( thedata, 0, theunpack, 0 );
> }

The problem is that thedata is not a MaxObject. It’s maybe easier to
use the script name like that:

function bang()
{
if( theunpack )
{
this.patcher.remove( theunpack );
}
theunpack = this.patcher.newdefault( 200, 200, "unpack", 0, 0);
theunpack.varname = "theunpack";
this.patcher.message("script", "connect", "thedata", 0, "theunpack",
0 );
}

HTH,
ej


June 10, 2007 | 5:47 pm

Try this:

inlets = 1;
outlets = 0;

var theunpack = 0;
var thedata = this.patcher.getnamed(‘thedata’);

function bang()
{
if (theunpack)
{
this.patcher.remove(theunpack);
}
theunpack = this.patcher.newdefault(200, 200, ‘unpack’, 0, 0);
this.patcher.connect(thedata, 0, theunpack, 0);
}

Now, if that works, and it should (although I haven’t tested it), it
should be clear what the problem was. What was it?

jb

Am 10.06.2007 um 19:37 schrieb Frans-Jan Wind:

> The .js file "dataToGen.js"
> inlets = 1;
> outlets = 0;
>
> var theunpack;
> //var thedata = this.patcher.thedata;
>
> function bang()
> {
> if( theunpack )
> {
> this.patcher.remove( theunpack );
> }
> theunpack = this.patcher.newdefault( 200, 200, ‘unpack’, 0, 0);
> this.patcher.connect( thedata, 0, theunpack, 0 );
> }


June 10, 2007 | 5:51 pm

On 10 juin 07, at 19:47, Jeremy Bernstein wrote:

> var thedata = this.patcher.getnamed(‘thedata’);

Yep that’s much better.

ej


June 10, 2007 | 5:58 pm

Thanks! Works like a charm!

So I need to make clear that it is a named object in max namespace.

Where can I find a reference of functions? like "getnamed"?

Frans-Jan


June 10, 2007 | 6:01 pm

JavaScriptInMax.pdf, in your Documentation folder!

jb

Am 10.06.2007 um 19:58 schrieb Frans-Jan Wind:

>
> Thanks! Works like a charm!
>
> So I need to make clear that it is a named object in max namespace.
>
> Where can I find a reference of functions? like "getnamed"?
>
> Frans-Jan


Viewing 6 posts - 1 through 6 (of 6 total)