discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Re: Should it be possible to reference a variable inside a module when the module is loaded by use?

NH
nop head
Thu, Sep 21, 2023 8:11 AM

I wouldn't expect it to work unless you used $generatecode or the module
was included instead of used.

On Thu, 21 Sept 2023 at 04:58, William F. Adams via Discuss <
discuss@lists.openscad.org> wrote:

---------- Forwarded message ----------
From: "William F. Adams" willadams@aol.com
To: "discuss@lists.openscad.org" discuss@lists.openscad.org
Cc:
Bcc:
Date: Thu, 21 Sep 2023 03:57:39 +0000 (UTC)
Subject: [OpenSCAD] Should it be possible to reference a variable inside a
module when the module is loaded by use?
Say I have a file with the lines:

use <pygcodepreview.scad>;

generategcode = true;

a = 300;

gcomment(str(a));

and pygcodepreview.scad is loaded from a library directory and contains:

module gcomment(comment) {
if (generategcode == true) {
echo("(",comment,")");
}
}

Should that work? If it should, why do I get the error:

Documents/OpenSCAD/libraries/pygcodepreview.scad, line 4

WARNING: Ignoring unknown variable 'generategcode' in file
../Documents/OpenSCAD/libraries/pygcodepreview.scad, line 8
I thought I had used such constructs in the past?

Did something change? Or am I getting this wrong somehow?
(I'm using the nightly build:
https://files.openscad.org/snapshots/OpenSCAD-2023.09.10-x86-64-Installer.exe
)
William

---------- Forwarded message ----------
From: "William F. Adams via Discuss" discuss@lists.openscad.org
To: "discuss@lists.openscad.org" discuss@lists.openscad.org
Cc: "William F. Adams" willadams@aol.com
Bcc:
Date: Thu, 21 Sep 2023 03:57:39 +0000 (UTC)
Subject: [OpenSCAD] Should it be possible to reference a variable inside a
module when the module is loaded by use?


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

I wouldn't expect it to work unless you used $generatecode or the module was included instead of used. On Thu, 21 Sept 2023 at 04:58, William F. Adams via Discuss < discuss@lists.openscad.org> wrote: > > > > ---------- Forwarded message ---------- > From: "William F. Adams" <willadams@aol.com> > To: "discuss@lists.openscad.org" <discuss@lists.openscad.org> > Cc: > Bcc: > Date: Thu, 21 Sep 2023 03:57:39 +0000 (UTC) > Subject: [OpenSCAD] Should it be possible to reference a variable inside a > module when the module is loaded by use? > Say I have a file with the lines: > > use <pygcodepreview.scad>; > > generategcode = true; > > a = 300; > > gcomment(str(a)); > > and pygcodepreview.scad is loaded from a library directory and contains: > > module gcomment(comment) { > if (generategcode == true) { > echo("(",comment,")"); > } > } > > Should that work? If it should, why do I get the error: > > Documents/OpenSCAD/libraries/pygcodepreview.scad, line 4 > > WARNING: Ignoring unknown variable 'generategcode' in file > ../Documents/OpenSCAD/libraries/pygcodepreview.scad, line 8 > I thought I had used such constructs in the past? > > Did something change? Or am I getting this wrong somehow? > (I'm using the nightly build: > https://files.openscad.org/snapshots/OpenSCAD-2023.09.10-x86-64-Installer.exe > ) > William > > > > > ---------- Forwarded message ---------- > From: "William F. Adams via Discuss" <discuss@lists.openscad.org> > To: "discuss@lists.openscad.org" <discuss@lists.openscad.org> > Cc: "William F. Adams" <willadams@aol.com> > Bcc: > Date: Thu, 21 Sep 2023 03:57:39 +0000 (UTC) > Subject: [OpenSCAD] Should it be possible to reference a variable inside a > module when the module is loaded by use? > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
WF
William F. Adams
Thu, Sep 21, 2023 10:39 AM

On Thursday, September 21, 2023 at 04:11:24 AM EDT, nop head nop.head@gmail.com wrote:

I wouldn't expect it to work unless you used $generatecode or the module was included instead of used.

That latter was it --- was using include, not use.
Thanks!
William

On Thursday, September 21, 2023 at 04:11:24 AM EDT, nop head <nop.head@gmail.com> wrote: >I wouldn't expect it to work unless you used $generatecode or the module was included instead of used. That latter was it --- was using include, not use. Thanks! William