Hello,
I’m writing a script with JS and writing a function that returns true if an event has a multi instrument on any parameter sheet. This is my current code:
function HasVariations( event )
{
var eventSheets = event.parameters;
eventSheets.push( event.timeline );
console.log("EVENT SHEETS: " + eventSheets );
for( var i = 0; i < eventSheets.length; i++ )
{
var instruments = eventSheets[ i ].modules;
console.log("INSTRUMENTS IN SHEET: " + instruments );
for( var j = 0; j < instruments.length; j++ )
{
if (instruments[ j ].entity === "MultiSound" )
{
return true;
}
}
}
return false;
}
If my eventSheets variable only includes a timeline, this works fine. But if I’m iterating over an action sheet or other parameter sheet then I get the following error:
TypeError: Result of expression 'instruments[ j ]' [undefined] is not an object., callstack:HasVariations(event = (ManagedObject:Event))
How could I make this code work when iterating over both timelines and param sheets?
Thanks in advance!
EDIT: actually the error only seems to happen when iterating over an Action Sheet - timelines and other parameter sheets work fine