I have a module that accepts children. I have confirmed that in the first call $children has the correct value (in my case 2, but it may be more or less in other cases). However, when I attempt to pass these to a recursive call using the following code:
MyModule(){for(i=[0:($children-1)])children(i);}
The $children then has a value of 1. I am guessing this has something to do with OpenSCAD attempting to join all children into a single child. I have tried to find a way to use the each(…) function to fix this, but that does not seem to work. Is there (or what is the best) way to pass children to a recursive call? Thanks!
Nathan Sokalski
njsokalski@hotmail.commailto:njsokalski@hotmail.com
There's no way to do what you want, for an arbitrary number of
children. You can do it for any finite number of children, by having an
"if" chain that looks at $children and calls MyModule() with children(0)
if it's 1, and calls MyModule() with { children(0); children(1); } if
it's 2, and so on. That's really tedious.
You are exactly correct that a "for", like any other OpenSCAD operation,
yields exactly one child.
And it kind of has to, because the child isn't evaluated until the
parent calls children(), and before that the parent is allowed to look
at $children to determine how many children there are.
And the children can't be evaluated until the parent calls children()
because they are allowed to consume $ variables that the parent has set.