Simple but head-aching connect() issue, urgent!

Apr 21, 2006 at 3:15pm

Simple but head-aching connect() issue, urgent!

Hi everyone

Sorry for troubling you with such simple questions, but I spend hours
on the problem and I couldn’t find any answers on the mailing-list or
in the JavaScriptInMaxPDF. Please!

I create a gate object in js, like this:
var theGate = this.patcher.newdefault(100 , 100, “gate”);

Now, I want to connect it to an dac~ obect i created in Max and named
(via. name…) “theDac”, and I guess Im supposed to do like this:
this.patcher.connect(theGate, 0, theDac, 0);

I get the error “Javascript ReferenceError: theDac is not defined”.

…why?

~Carl Email

#25564
Apr 21, 2006 at 5:45pm

what you set in Max-land is the “varname” property, and what the
function “connect” uses is a javascript representation of a max
object, very different.

you need this code (or something similar) to get the js max object
associated with the varname “theDac”:

var jsDac = this.patcher.getnamed(“theDac”);
this.patcher.connect(theGate, 0, jsDac, 0);

-evan

#75394
Apr 22, 2006 at 7:30am

Thank you Evan

I tried getnamed() like you propose, but then Max crashes when I
connect().
If I ask for the content of jsDac by post(jsDac) I get the reply
“jsobject 0″.
Any ideas?

~Carl Email

#75395
Apr 22, 2006 at 8:36am

If you post an example patch and JS file it will be much easier to help.

best,
wes

#75396
Apr 22, 2006 at 8:41am

Is your “theDac” in the same patcher level as the js object? It should work
then. Maybe try a different name? If you don’t want max to crash do
something like this:

if(jsDac){
//connect
}
else
post(“can’t find dac!n)”

Deleting or connecting objects that don’t exist leads to crashes in js, so
you have to always check for yourself. I’d like to see this get changed to a
friendly error message one day..:-). thispatcher scripts don’t crash on
these things.

hth, Thijs

#75397
Apr 22, 2006 at 9:23am

#75398
Apr 22, 2006 at 9:41am

If you want help with your old patch explain what’s bugging you or send the
patch and I’ll have a look. Otherwise good luck.

Best, Thijs

#75399

You must be logged in to reply to this topic.