We value your input!
Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey

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

Incomprehensible grammar problem

Anonymous
Not applicable
HI!
I have been programming for a long time, and I can't understand some basic errors in GDL. E.g:

x  =  0.38
x2 = 1.08
if x=x2 then print 1 else print 2
check script : use of real types can result...
???
I can't use the equal sign, so every time I use very cumbersome code to judge
I really can't stand this problem.

I can only write this way.

x  =  0.38
x2 = 1.08
if x-x2 then 
  print 2
else
  print 1
endif
5 REPLIES 5
Lingwisyer
Guru
I have no issue using the equal sign. I do believe I have an issue doing a If - Then - Else on a single line. I can do an If - Then on a single line, but if I add an Else I need to split the actions into separate lines. I will check tomorrow if I remember...



Ling.

AC22-23 AUS 7000Help Those Help You - Add a Signature
Self-taught, bend it till it breaksCreating a Thread
Win11 | i9 10850K | 64GB | RX6600 Win10 | R5 2600 | 16GB | GTX1660
Barry Kelly
Moderator
There is no problem with the if/then/else all on one line.
It is simply a warning to say it is not a good idea to equate numbers with each other.
Your original script may work, but it is not a good idea to use it unless you can be sure of the accuracy of the numbers.

I don't understand it all myself, but I believe there is a level of accuracy that GDL uses.
Have a look at this....


You can write an equation that does not use = and you can specify the level of accuracy that you want to compare.


Barry,
One of the forum moderators.
Versions 6.5 to 27
i7-10700 @ 2.9Ghz, 32GB ram, GeForce RTX 2060 (6GB), Windows 10
Lenovo Thinkpad - i7-1270P 2.20 GHz, 32GB RAM, Nvidia T550, Windows 11
Anonymous
Not applicable
"=" The equal sign can only support integers
So I can only use the greater than or less than the number to judge, can not use the equal sign, so very inaccurate

I don't report errors when I write like this.

     if  x<= 0.1 and x>0.09 then print 1
Lingwisyer
Guru
Oh. That error. For user inputs, I have instead been writing
If a <> b then d else c 



Ling.

AC22-23 AUS 7000Help Those Help You - Add a Signature
Self-taught, bend it till it breaksCreating a Thread
Win11 | i9 10850K | 64GB | RX6600 Win10 | R5 2600 | 16GB | GTX1660
Ralph Wessel
Mentor
The key issue here is precision. It's generally not helpful to issue architectural documentation with precision smaller than 1mm, and construction tolerances are generally not that tight. You want to be aware of that when scripting for objects because it's very easy to be far more precise than is helpful to the user.

For example, if an object is supposed to display a specific label or illustration if the length is 5m, what should happen if the length is 5.00001m, i.e.a difference of 0.01mm? The user won't be able to detect that difference visually or using dimensions because ARCHICAD won't display dimensions to that precision. So the user might have something which looks exactly like 5m, but the object acts as though it isn't.

This is why ARCHICAD is warning you when you say things like:
if length = 5 then
. Specify a level of precision in your script and then use it for all floating point comparisons, e.g.:
eps = 1e-4
if abs(length - 5) < eps then
GS is right in calling this to your attention – handling precision incorrectly can be really irritating (or costly) for the end user otherwise.
Ralph Wessel BArch
Software Engineer Speckle Systems