Copy link to clipboard
Copied
I have a function that I'm trying to use that I am bringing into my script with #include. In the function, it calls itself recursively. When I have had this function embedded in the script normally it works fine. However, now that I'm using it externally it seems to stall out with no errors when it references itself. Do I need to do something differently?
Here's my standalone function for example:
{
function findItem(itemName, sendToQ, iType){ //loops through the project looking for items with a certain name
writeLn("Searching for: " + itemName);
for(var x = 1; x <= app.project.numItems; x++) {
var curItem = app.project.item(x);
// $.writeln("Finding: " + curItem.name);
if(iType == "comp") {
if(curItem instanceof CompItem && curItem.name == itemName) {
var itemOut = curItem
}
} else if(iType == "folder") {
if(curItem instanceof FolderItem && curItem.name == itemName) {
var itemOut = curItem
}
} else if(iType == "footage") {
if(curItem instanceof FootageItem && curItem.name == itemName) {
var itemOut = curItem
}
}
}
if(sendToQ == true && iType == "comp") {
app.project.renderQueue.items.add(itemOut); //add item to the Render Queue
app.project.renderQueue.showWindow(false); //hide the RQ window
}
if(!itemOut) {
for(var n = 0; n < nameMatchNew.length; n++){ //loop through the list of words already input by user
if(itemName == nameMatchOrig[n]){
itemOut = findItem(nameMatchNew[n], false, iType );
writeLn("Found a match for a previous name to find");
}
}
if(!itemOut){ //if the matching test didn't work, ask the user
itemOut = findItem(prompt("Unable to find a " + iType + " named '" + itemName + "'\n The script may have errors from this point forward\n"
+"Please give the script a new "+ iType +" to search for instead of: " +itemName, itemName), false, iType);
writeLn("User gave: " + itemOut.name);
nameMatchOrig.push(itemName);
nameMatchNew.push(itemOut.name);
}
//alert("Unable to find a " + iType + " named '" + itemName + "'\n The script may have errors from this point forward");
}
$.writeln("Found " + itemOut.name + " " + iType);
return itemOut; //returns an item
} //end finditem
}
Have something to add?