We value your input! Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey
2022-11-02 05:26 AM
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?
Solved! Go to Solution.
2022-11-02 06:04 AM
Use macros if you want to access them from multiple objects.
Use sub-routines if just within the one object.
Barry.
2022-11-02 06:04 AM
Use macros if you want to access them from multiple objects.
Use sub-routines if just within the one object.
Barry.
2022-11-02 10:23 AM
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...
2022-11-02 10:38 AM
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.
2022-11-02 11:06 PM
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.
2022-11-02 11:48 PM
internal flow control statements do not have encapsulation.
if you use an external macro using the "call" function, that does have encapsulation.
and remember script order
2022-11-03 02:46 AM
@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.
2022-11-03 03:03 AM
yeah it's kinda making sense now. I just figured that everything is the input and everything is the output.
2022-11-03 09:22 PM
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.
2022-11-04 01:02 AM
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.