find and return scripting name of specific object issue.

Aug 18, 2013 at 1:00pm

find and return scripting name of specific object issue.

Hi guys,

I’m getting back into js again to scrape data on some of my patches for a sort of adaptive master control patch.

Anyway the first problem I’ve come into is in the code below.

From my understanding (providing my patch has a pattrstorage in it, which it does) the variable ‘thePattr’ should be assigned to the return value of the ‘findPattr’ function surely?
Unless I’ve misunderstood something about returns.

I seem to get undefined.

However, if I put ‘post(“pattrName ” + a.varname);post();’ before returning in the ‘findPattr’ function I get the scripting name I’m looking for.

Any ideas?

function getPattr(){
var thePattr = this.patcher.apply(findPattr);

post(“thePatt ” + thePatt.varname);post();
}

function findPattr(a){
if (a.maxclass === “pattrstorage”) {
return a;
}
}

#259210
Aug 18, 2013 at 1:26pm

Apologies, obvious typo, the problem still remains:

function getPattr(){
var thePatt = this.patcher.apply(findPattr);

post(“thePatt ” + thePatt.varname);post();
}

function findPattr(a){
if (a.maxclass === “pattrstorage”) {
return a;
}
}

#259212
Aug 19, 2013 at 1:12am

Hi, the call to apply is not going to return the instance you are expecting, you need to perform all the logic inside your findPattr() function,

i.e.

function findPattr(a){
if (a.maxclass === “pattrstorage”) {
// do your logic here
}
}

L

#259236

You must be logged in to reply to this topic.