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

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
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 25
Dell XPS- i7-6700 @ 3.4Ghz, 16GB ram, GeForce GTX 960 (2GB), Windows 10
Dell Precision 3510 - i7 6820HQ @ 2.70GHz, 16GB RAM, AMD FirePro W5130M, Windows 10

@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 25
Dell XPS- i7-6700 @ 3.4Ghz, 16GB ram, GeForce GTX 960 (2GB), Windows 10
Dell Precision 3510 - i7 6820HQ @ 2.70GHz, 16GB RAM, AMD FirePro W5130M, Windows 10

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 am up to page 4,078 of Archicad 26 Reference Guide, (Worksheet and Detail Tool Settings), but i got to read it all 😞


@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 25
Dell XPS- i7-6700 @ 3.4Ghz, 16GB ram, GeForce GTX 960 (2GB), Windows 10
Dell Precision 3510 - i7 6820HQ @ 2.70GHz, 16GB RAM, AMD FirePro W5130M, Windows 10

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.

Mostly AC 26 on Mac | Author of SelfGDL | Developer of the GDL plugin for Sublime Text |
«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 25 / Windows 10

Still looking?

Browse more topics

Back to forum

See latest solutions

Accepted solutions

Start a new discussion!