Hello,
I am new to OpenSCAD and functional programming, so bear with me.
Is it possible to pass a parameter to a module using the children() feature?
module test(which)
{
echo(which);
}
module main()
{
children(0)(1); // error here
children(0,2); // and here
}
main()
{
test();
}
This doesn’t work, but should illustrate what I’m trying to do. An alternate approach that does work, but isn’t quite what I want:
module test(which)
{
echo(which);
}
module main()
{
children(0);
children(1);
}
main()
{
test(0);
test(1);
}
Thanks,
Mark
On 11/10/2024 8:37 PM, Mark Erbaugh via Discuss wrote:
Is it possible to pass a parameter to a module using the children()
feature?
Not directly, because the things that children() processes are module
invocations rather than modules per se. There is, however, an indirect
mechanismsusing $ variables.
module foo() {
echo($i);
}
module bar() {
children($i = 1);
children($i = 2);
}
bar() {
foo();
}
Thanks for the tip. I expanded your example slightly to do what I needed.
module foo() {
if ($i == 1)
echo("This is foo() level 1.");
else
echo("This is foo() not level one.");
}
module bar() {
echo(str("bar ", $i));
}
module main() {
children(0, $i = 1);
children(0, $i = 2);
children(1, $i = 1);
children(1, $i = 2);
}
main() {
foo();
bar();
}