|
Check if input connected to javascript patchIs there a way to check if an input has been connected to the javascript patch and act accordingly so that it doesn't crash? I'm developing a javascript patch that mixes 3 structures together defined by a "map" structure. I use a switch to check if the map wants structure 1, 2, or 3 for that index. However, the patch doesn't run if I don't connect all three structures. I tried checking if the input is 'defined' but that didn't seem to make a difference. for(i=0;i<numChannels;i++) { var index = mixStructure[i]; switch(index) { case 0 : result.outputStructure[i] = 0; break; case 1 : result.outputStructure[i] = inputStructure1[i]; break; case 2 : result.outputStructure[i] = inputStructure2[i]; break; case 3 : if (typeof window.inputStructure3 !== 'undefined') { result.outputStructure[i] = inputStructure3[i]; } break; default: result.outputStructure[i] = 0; } } Any ideas?
|
'undefined' is the string constant "undefined" -- the "undefined" object is simply "undefined" (without single quoted, double quotes, etc.).
in QC, unattached inputs are usually not "undefined", but "null".
The above prints "oh snap!" when no input structures are attached.
Can't you just use something like "if(inputStructure[i]"! I think it'll work.
Just checked and it works (attached a sample comp)