newdefault argument issues
Hi everyone,
I'm trying to make a super simple js script in Max to make an unpack object of variable length depending on the list input to the js object. I've done some js things before in Max (and not in Max!) and feel relatively secure with in, so either I'm missing something super obvious or something doesn't work in a logical way!
I've tried the following:
unp = this.patcher.newdefault(1000, 1000, "unpack", 0 0 0);
unp = this.patcher.newdefault(1000, 1000, "unpack", "0 0 0");
unp = this.patcher.newdefault(1000, 1000, "unpack", "0 0 0");
However, the first option throws an error (js: autounpack.js: Javascript SyntaxError: missing ) after argument list, line 14), and the second and third options reproduce exactly what is written including the quote marks, which means the unpack object is created with only one outlet (and isn't super useful!). I've also tried this with the sel object so that I end up with sel 0 1 2, and I get similar results.
If anyone could tell me what I'm missing so I can stop banging my head against a brick wall that would be amazing!
Thanks!
You're missing commas in the first one. Fortunately if you provide an array as an argument in new default it's values are unpacked.
// Commas help!
var unp = this.patcher.newdefault(100, 100, "unpack", 0, 0, 0);
// Arrays will be 'unpacked' into arguments...
unp = this.patcher.newdefault(100, 140, "unpack", [0,0,0,0] );
// So this is pretty easy..
var arr = new Array(72)
for (var i = 0; i<arr.length; i++ ) {
arr[i] = i
}
unp = this.patcher.newdefault(100, 180, "unpack", arr)
}
ah! I'd missed that each argument is separated by a comma... absolute rookie error! Thanks so much!