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

GDL
About building parametric objects with GDL.
SOLVED!

is there a DEF in gdl? I mean defining functions.

Jack D
Booster

I've been hearing time and time that GDL is based of BASIC. I know that it doesn't have everything that BASIC has but I'm also a bit weirded out that GDL doesn't have basic programming structure like functions. I haven't seen any mention of defining functions in the GDL resource. They do however have mentioned functions to basic stuff but not me creating one.

 

Is there anyway to create functions? seems like macros are the closest to functions? 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Solution
Barry Kelly
Moderator

Use macros if you want to access them from multiple objects.

Use sub-routines if just within the one object.

 

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

View solution in original post

10 REPLIES 10
Solution
Barry Kelly
Moderator

Use macros if you want to access them from multiple objects.

Use sub-routines if just within the one object.

 

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

@Barry Kelly,

 

I'm just rebounding on your reply about macros as I would like to know if macros should be categorized as "macro" ? I usually keep the same subtype as the actual object and make it not placeable but is it bad practice ? I do so because the macro seems to lose some of the default parameters of specific subtypes while doing so...

What you are doing is fine.

A macro can be any object, even a placeable one.

But if you don't want it to show in the library object dialogue, make it not placeable as you have done.

 

The sub-type does affect the default parameters.

So yes, just choose the sub-type that suits you best - the same sub-type as the CALLing object is ideal as you have discovered.

 

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

So are you saying that

 

```

x=1

gosub "potato"

russet = x

end

 

"potato":

    x=x+1

return

```

so you're saying that "russet" in line 3 is equivalent to 2? yeah I'm still wrapping my head around how data flow in Archicad. I had a conversation about this with my colleague and how he did our library. I think I got too used to other languages that needs you to be more explicit with it's input and output. The other thing that confuses me is if subroutines follow encapsulation. 

internal flow control statements do not have encapsulation.

AllanP_1-1667428868462.png

 

 

if you use an external macro using the "call" function, that does have encapsulation.

AllanP_0-1667428651142.png

 

and remember script order

AllanP_3-1667429297972.pngAllanP_4-1667429317364.png

 

I have been using ArchiCAD continually since ArchiCAD 4.5, 4.5.5, 5, 5.1, 6, 6.5, 7, 8, 8.1, 9, 10, 11, 12, 13, 15, 18, 21, 22, 25, now testing 27
Member of Architalk since 2003, but missed the migration to Graphisoft.
(where have all my original posts gone?)

@Jack D wrote:

so you're saying that "russet" in line 3 is equivalent to 2?


Exactly.

x was equal to 1.

You 'GOSUB'ed to a routine that added 1 to the value of x and then returned to continue the original script.

You then say russet equals x and as x equals 2, russet now equals 2 as well.

 

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

yeah it's kinda making sense now. I just figured that everything is the input and everything is the output.

As others already said, there are subroutines and macros, and you can utilize them to suit your needs. However just keep in mind that subroutines do not create a scope, which means that all variables are always global and can be altered in a subroutine.

Lucas Becker | AC 27 on Mac | Author of Runxel's Archicad Wiki | Editor at SelfGDL | Developer of the GDL plugin for Sublime Text | My List of AC shortcomings & bugs | I Will Piledrive You If You Mention AI Again |

POSIWID – The Purpose Of a System Is What It Does /// «Furthermore, I consider that Carth... yearly releases must be destroyed»
neilmcallister
Booster

The problem is that GDL is a really old language (I think it first appeared in 1983) and therefore is based on really old BASIC.  Structured programming concepts like functions unfortunately come from later versions of BASIC.  It seems that a lot of extra features have been added but the underlying language structure hasn't been significantly improved.

Archicad 26 / Windows 11