I have a multi-file project where a makefile invokes the files
separately with various variable overrides, but I can also call them
from one "central" file to see how it all fits together.
I'm using special variables with the intention that the central file can
easily override values elsewhere (with differing values between calls to
various modules) but I'm having to jump through hoops.
Consider this.
// a.scad
use <b.scad>
$a =4;
echo ("Value in a", $a);
module_in_b ();
// b.scad
$a = 8;
module module_in_b () {
echo ("Value in module_in_b", $a);
}
Expected value when a.scad is opened in OpenSCAD is that 4 will be
echoed, but I get 8.
ECHO: "Value in a", 4
ECHO: "Value in module_in_b", 8
Changing the call line to -
module_in_b ($a=$a);
makes it work as expected, but surely special variables are supposed to
be passed down like this automagically?
It's a pain as I have a good half dozen variables and every call is now
going to need "decorating" with lots of $xyz=$xyz at great length. I was
delighted when I "discovered" special variables and realised that all my
previous passing down of normal ones could be ripped out!
I can't comment on the deliberate-ness of the behavior, but if you replace the "use" with "include" you'll get the behavior you expected. It seems that in the same way use doesn't pass variable definitions back to the file that use'd it, special variables don't get passed into use. include seems to just merge all the files together into one flattened file, so it works just like a single file would.
I had started out with use since I only wanted modules and functions to be created by my libraries, but quickly ran into the same issue with special variables not passing as expected, and just converted everything to include and my problems went away. Just need to be a bit more careful with normal variables in the include'd files.
On Jul 16, 2017, at 8:32 AM, Ian Oliver lists@foxhill.co.uk wrote:
I have a multi-file project where a makefile invokes the files separately with various variable overrides, but I can also call them from one "central" file to see how it all fits together.
I'm using special variables with the intention that the central file can easily override values elsewhere (with differing values between calls to various modules) but I'm having to jump through hoops.
Consider this.
// a.scad
use <b.scad>
$a =4;
echo ("Value in a", $a);
module_in_b ();
// b.scad
$a = 8;
module module_in_b () {
echo ("Value in module_in_b", $a);
}
Expected value when a.scad is opened in OpenSCAD is that 4 will be echoed, but I get 8.
ECHO: "Value in a", 4
ECHO: "Value in module_in_b", 8
Changing the call line to -
module_in_b ($a=$a);
makes it work as expected, but surely special variables are supposed to be passed down like this automagically?
It's a pain as I have a good half dozen variables and every call is now going to need "decorating" with lots of $xyz=$xyz at great length. I was delighted when I "discovered" special variables and realised that all my previous passing down of normal ones could be ripped out!
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
I work around this as follows:
In b.scad I would do
a = $a == undef ? 8 : $a.
Then use a in my code but set $a if I want to override it.
On 17 July 2017 at 00:40, William Ferry woferry@mac.com wrote:
I can't comment on the deliberate-ness of the behavior, but if you replace
the "use" with "include" you'll get the behavior you expected. It seems
that in the same way use doesn't pass variable definitions back to the file
that use'd it, special variables don't get passed into use. include seems
to just merge all the files together into one flattened file, so it works
just like a single file would.
I had started out with use since I only wanted modules and functions to be
created by my libraries, but quickly ran into the same issue with special
variables not passing as expected, and just converted everything to include
and my problems went away. Just need to be a bit more careful with normal
variables in the include'd files.
On Jul 16, 2017, at 8:32 AM, Ian Oliver lists@foxhill.co.uk wrote:
I have a multi-file project where a makefile invokes the files
separately with various variable overrides, but I can also call them from
one "central" file to see how it all fits together.
I'm using special variables with the intention that the central file can
easily override values elsewhere (with differing values between calls to
various modules) but I'm having to jump through hoops.
Consider this.
// a.scad
use <b.scad>
$a =4;
echo ("Value in a", $a);
module_in_b ();
// b.scad
$a = 8;
module module_in_b () {
echo ("Value in module_in_b", $a);
}
Expected value when a.scad is opened in OpenSCAD is that 4 will be
echoed, but I get 8.
ECHO: "Value in a", 4
ECHO: "Value in module_in_b", 8
Changing the call line to -
module_in_b ($a=$a);
makes it work as expected, but surely special variables are supposed to
be passed down like this automagically?
It's a pain as I have a good half dozen variables and every call is now
going to need "decorating" with lots of $xyz=$xyz at great length. I was
delighted when I "discovered" special variables and realised that all my
previous passing down of normal ones could be ripped out!