Libraries & objects
About Archicad and BIMcloud libraries, their management and migration, objects and other library parts, etc.

invalid non-declared variable

rocorona
Booster
can you reproduce/explain this behavior?

In a master script:

DEFINE TRANSLUCENT_FILL "test1" zero,2,3,4,5,6,7,8, 0.25
zero=0
DEFINE TRANSLUCENT_FILL "test2" zero,2,3,4,5,6,7,8, 0.25


when checking these instructions, ArchiCAD reports "insufficient parameters" for the first DEFINE, where a non-declared variable is used.
Thes second one is copy-pasted, to avoid any possible difference, but the zero is declared, and it works.

--Roberto Corona--
_________________

--Roberto Corona--
www.archiradar.com
AC18 - ITA full on Win10
_________________
_________________
13 REPLIES 13
David Maudlin
Virtuoso
Roberto:

My guess is that the first (undeclared) "zero" is read as a string expression (text) where ArchiCAD expects a numeric expression (number). Defining "zero" as a number corrects this error.

David
David Maudlin / Architect
www.davidmaudlin.com
Digital Architecture
AC27 USA • iMac 27" 4.0GHz Quad-core i7 OSX11 | 24 gb ram • MacBook Pro M3 Pro | 36 gb ram OSX14
rocorona
Booster
this could be true, but we know that undeclared variables are initialized as numbers.
And, in fact, if I test it (at the script first line) with VARTYPE (zero) it says is "1" (number) not "2" (string).

Just discovered that an explicit use of "zero" as number (before the first DEFINE command) seems to "force" a declaration.
For examples, using a simple

x=zero+zero

the error message disappears.
_________________

--Roberto Corona--
www.archiradar.com
AC18 - ITA full on Win10
_________________
_________________
Anonymous
Not applicable
rocorona wrote:
this could be true, but we know that undeclared variables are initialized as numbers.
And, in fact, if I test it (at the script first line) with VARTYPE (zero) it says is "1" (number) not "2" (string).

Just discovered that an explicit use of "zero" as number (before the first DEFINE command) seems to "force" a declaration.
For examples, using a simple

x=zero+zero

the error message disappears.
Roberto,

I would have answered the same as David, pat1 to pat8 are integers. Is there something else to understand?
But your second post makes more sense.

Yes, I get the same result/alerts.
May be zero is a reserved keyword for GS programmers. Anyway, thanks for the info.
David Maudlin
Virtuoso
There are a number of ways to initialize the variable.
1. Add a new parameter to the part with the Variable "zero".
2. At the beginning of the Master Script add "zero=zero".
3. At the beginning of the Master Script add "Print zero".

I am sure there are more, for what it is worth.

David
David Maudlin / Architect
www.davidmaudlin.com
Digital Architecture
AC27 USA • iMac 27" 4.0GHz Quad-core i7 OSX11 | 24 gb ram • MacBook Pro M3 Pro | 36 gb ram OSX14
ztaskai
Graphisoft Alumni
Graphisoft Alumni
When using numeric variables, you should initialize them before their value is used for the first time. The good way to do this is the following for a variable which is OK to start from a given constant:
isOkToStartFomZero = 0
shouldStartFrom3 = 3
AC13 will have a GDL warning to warn developers about uninitialized variables. It helps you stay in picture about what is happening.

Regards,
Zsolt
Zsolt Táskai
ArchiCAD Development - GDL Team
AC13, AC14 and upwards...
Anonymous
Not applicable
I checked, zero is not a reserved keyword.
x = zero+zero is the same as writing zero = 0
zero can be replaced by any variable.
ztaskai wrote:
When using numeric variables, you should initialize them before their value is used for the first time. The good way to do this is the following for a variable which is OK to start from a given constant:
isOkToStartFomZero = 0
shouldStartFrom3 = 3
AC13 will have a GDL warning to warn developers about uninitialized variables. It helps you stay in picture about what is happening.

Regards,
Zsolt
Good point.
Anonymous
Not applicable
Hi Zsolt,
ztaskai wrote:
AC13 will have a GDL warning to warn developers about uninitialized variables. It helps you stay in picture about what is happening.
Just to tease us a little... In a scale of -10 to 10 which do you think will be our impression about AC13 GDL new features?...
Thank you for the news!
Karl Ottenstein
Moderator
ztaskai wrote:
AC13 will have a GDL warning to warn developers about uninitialized variables.
That's great news, Zsolt.

The old behavior of an uninitialized variable being treated as a zero-value has 'bitten' too many newcomers to GDL, and even old timers. A simple typo results in a variable with a zero value which can take considerable time to track down and debug. The warning will be a great help to everyone.

Certainly, some old (user written) library parts will need to have initialization statements added, but that is for the good IMHO. It was lazy programming to intentionally assume an uninitialized variable would be zero.

Thanks,
Karl
One of the forum moderators
AC 27 USA and earlier   •   macOS Ventura 13.6.6, MacBook Pro M2 Max 12CPU/30GPU cores, 32GB
Laszlo Nagy
Community Admin
Community Admin
ztaskai wrote:
AC13 will have a GDL warning to warn developers about uninitialized variables.
What would also be good is to extend this behavior to all error cases in GDL, not just uninitialized variable. I could even imagine ArchiCAD giving an advice in the error message on how to fix it.
For example, when the "Fill not found at line xxx" message, the message could also say that this and this parameter or line of code calls for a fill with this fill index, but it does not exist, check in your Fill Types Dialog or the Attribute Manager or whatever blablabla.
The point would be to enable people to solve the problem themselves.
Loving Archicad since 1995 - Find Archicad Tips at x.com/laszlonagy
AMD Ryzen9 5900X CPU, 64 GB RAM 3600 MHz, Nvidia GTX 1060 6GB, 500 GB NVMe SSD
2x28" (2560x1440), Windows 10 PRO ENG, Ac20-Ac27