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

GDL
About building parametric objects with GDL.
SOLVED!

Question about Arrays & Subroutines

Nader Belal
Mentor
Hi there,

I would like to ask why the creation of arrays in a sub-routine in Parameter script as in the following example is generating an error ("Incompatible array dimensions")


some script

if condition is met then
	gosub 001

	_tempArray = _origArray		!<--both arrays are one dimension
endif

some script

end

001:

dim _tempArray

return

A good friend of mine have once told me that I´m so brute that I´m capable of creating a GDL script capable of creating GDLs.
1 ACCEPTED SOLUTION

Accepted Solutions
Solution
Jochen Suehlo
Moderator
In my experience it happens, that arrays defined in a subroutine where not recognized in parts of scripts that are above the subroutine (in the text order).
Example:
gosub 100
_newVALUE = _tempArray[1]		
end
100:
dim _tempArray[]
_tempArray[1] = 2
return
But if you change this into this, it works:
gosub 100
gosub 200
end
100:
dim _tempArray[]
_tempArray[1] = 2
return

200:
_newVALUE = _tempArray[1]	
return
This is a weird thing, but I think, it is a bug.
Jochen Suehlo . AC12-27 . MAC OSX 14.4 . WIN11
GDL object creation: b-prisma.de

View solution in original post

4 REPLIES 4
Solution
Jochen Suehlo
Moderator
In my experience it happens, that arrays defined in a subroutine where not recognized in parts of scripts that are above the subroutine (in the text order).
Example:
gosub 100
_newVALUE = _tempArray[1]		
end
100:
dim _tempArray[]
_tempArray[1] = 2
return
But if you change this into this, it works:
gosub 100
gosub 200
end
100:
dim _tempArray[]
_tempArray[1] = 2
return

200:
_newVALUE = _tempArray[1]	
return
This is a weird thing, but I think, it is a bug.
Jochen Suehlo . AC12-27 . MAC OSX 14.4 . WIN11
GDL object creation: b-prisma.de
Nader Belal
Mentor
@Joachim Suehlo

Thank you a lot.
A good friend of mine have once told me that I´m so brute that I´m capable of creating a GDL script capable of creating GDLs.
leceta
Expert
From the book GDL Handbook, by Andrew Watson, 3.5.Scope, pages 36-37

Array variables have some interesting characteristics when it comes to scope. You must define an array before you can use it, which stands to reason. You can define an array variable in a sub-routine (we’ll discuss sub-routines later) but it’s best to define arrays in the main script. If you define an array variable in a sub-routine and then try to use it in the main script, error messages will pop up when you try to save the object.

and later:

The variable must be declared at a point in the script that comes both physically and logically ahead of the point at which it is used.
Peter Baksa
Graphisoft
Graphisoft
Joachim wrote:
This is a weird thing, but I think, it is a bug.
This isn't a bug, it's a limitation. The order of statements can depend on parameters, it is only known at run-time. Variables mustn't change their types during run, the best the interpreter can do is check the code line-by-line (there are simple cases when the order of execution is evident, but it can get complicated very easily). If it didn't do this check, it would be possible to get error messages only by some parameter states, which would make them very hard to detect and understand.
Péter Baksa
Software Engineer, Library as a Platform
Graphisoft SE, Budapest