cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 
Design forum

invalid non-declared variable

rocorona
Contributor
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

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

AC26 USA • iMac 27" 4.0GHz Quad-core i7 | 24 gb ram • MacBook Pro 2.8GHz | 16 gb ram • OSX10.15.7

rocorona
Contributor
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.

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

AC26 USA • iMac 27" 4.0GHz Quad-core i7 | 24 gb ram • MacBook Pro 2.8GHz | 16 gb ram • OSX10.15.7

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 26 USA and earlier   •   MacOS 11.6.8, iMac Pro

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.
....................................................................................................
Get Archicad Tips at https://twitter.com/laszlonagy
AMD Ryzen 1700X CPU, 48 GB RAM, Nvidia GTX 1060 6GB, 500 GB NVMe SSD
2x28" (2560x1440), WIN10 PRO ENG, AC20-AC26
Loving Archicad since 1995

Anonymous
Not applicable
Hi Laszlo,

The lack of detail in a error message is directed linked to the enthusiasm for a software...
I mean... a new user who reads the actual AC error messages looses a considerable portion of enthusiasm as it doesn't point to a detail solution for the error.
Huge impact and very simple to implement...
Good idea Laszlo!...

rocorona
Contributor
ztaskai wrote:
When using numeric variables, you should initialize them before their value is used for the first time.
[...]
Zsolt


As an old BASIC programmer, I absolutely agree that declared variables are "safer" and a good programming practice.
I only noticed that strangeness when copying-pasting the syntax from the GDL manual for a quick test.
The worst, as pointed out by others, is the cryptic error message ("insufficient parameters").

Anyway, the same use of an undeclared variable, works without problems in "old" Define Fill.

DEFINE FILL "testfill" undeclared, 2, 3, 4, 5, 6, 7, 8,
1, 0.0, 2,
0.1, 0.0, 0.0, 0.0, 0,
0.1, 90.0, 0.0, 0.0, 0,
1.0, 1.0
_________________

--Roberto Corona--
www.archiradar.com
AC18 - ITA full on Win10
_________________
_________________

ztaskai
Graphisoft Alumni
Graphisoft Alumni
Hi all,

Yes, non-declared variables will keep working. They are always considered as numeric variables with the value of zero.

And yes, we should have better error messages. I don't think we can change them all in one big chunk but we'll try to go in the proposed clearer direction with new messages and when touching old ones.

About AC13 and GDL... I'm really happy about the fixes and changes we make but I'm afraid only one of the fundamental problems will be solved. I will post a summary about the little and bigger changes when we enter alpha phase. Feel free to remind me in case I appear to forget about that.

Regards,
Zsolt
Zsolt Táskai
ArchiCAD Development - GDL Team
AC13, AC14 and upwards...

Anonymous
Not applicable
Thank you very much for your feedback Zsolt.
ztaskai wrote:
I will post a summary about the little and bigger changes when we enter alpha phase.
I'm looking foward!

Didn't find the answer? Start a new discussion

Labels

Still looking?

Browse more topics

Back to forum

See latest solutions

Accepted solutions

Start a new discussion!