Message 1 of 7
Recursive Function Problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I have a function that calls itself in a for loop. That all works fine, except for the last loop. I'm looping through a hierarchy of dummy & mesh objects. I'm collapsing the mesh objects into a new mesh and then deleting the dummy nodes at the end of the collapsing operation. So on the first run of the function it calls itself, to handle the first node it finds in the for loop that has children. It appears that Maxscript does not finish executing the remainder of the function past this point, until every recursive iteration in the for loop has finished. That's Ok I guess. At the end of the function after this for loop, there is code that deletes the dummy objects that have been stored in an array. This block of code only needs to run after all of the recursive iterations are finished. The code block has an if statement that compares the number of iterations against the number of children the top level node has, and if they are equal, it executes the code. The problem is that this evaluates to true on the last iteration of the for loop, and so it executes, and then again once the original call to the function finishes executing. That is a problem, and I do not know how to resolve it. It's probably simple, and I don't see it because I've been staring at it all day, but if anyone has an idea let me know.
Below is a skeleton of what I am attempting.
thx
I have a function that calls itself in a for loop. That all works fine, except for the last loop. I'm looping through a hierarchy of dummy & mesh objects. I'm collapsing the mesh objects into a new mesh and then deleting the dummy nodes at the end of the collapsing operation. So on the first run of the function it calls itself, to handle the first node it finds in the for loop that has children. It appears that Maxscript does not finish executing the remainder of the function past this point, until every recursive iteration in the for loop has finished. That's Ok I guess. At the end of the function after this for loop, there is code that deletes the dummy objects that have been stored in an array. This block of code only needs to run after all of the recursive iterations are finished. The code block has an if statement that compares the number of iterations against the number of children the top level node has, and if they are equal, it executes the code. The problem is that this evaluates to true on the last iteration of the for loop, and so it executes, and then again once the original call to the function finishes executing. That is a problem, and I do not know how to resolve it. It's probably simple, and I don't see it because I've been staring at it all day, but if anyone has an idea let me know.
Below is a skeleton of what I am attempting.
thx
function collapseSelectedDummy theNode =
(
for c in nodeChildren do
(
--here I'm processing the nodes.
--if it is a mesh it gets collapsed
--if it is a dummy node then it calls this function again
--I'm also keeping a tally of the nodes processed with the variable dummyChildrenProcessed
)
--this code only needs to execute once, but it is getting called twice
--here I am deleting out the dummy nodes
--it compares the number of processed nodes against the number of children
--the selected scene node has
if dummyChildrenProcessed == selectedNodeNumChildren then
(
for i in dummiesToDelete do
(
delete i
)
)
