Initializing an array in a function?

BlitzMax Forums/BlitzMax Beginners Area/Initializing an array in a function?

Gabriel(Posted 2006) [#1]
I need to have a function which takes an array as a parameter and initializes it, as well as putting stuff in it. Returning the array is not really an option, as I'm trying to keep the interface the same as the dll I'm wrapping.

EG:

Type SomeType
   Field SomeStuff:Int
   Field SomeOtherStuff:Float
End Type

Global P:SomeType[]
Global ArraySize:Int
InitArray(P,ArraySize)


Function InitArray(A:SomeType[],Sz:Int Var)
   Local Size=Getsize() ' FUNCTION SOMEWHERE ELSE
   A=New SomeType[Size]
   Sz=Size
End Function


But of course, I get an attempt to access array index out of bounds if I try to read or write to the array. I'm sure this is easy and I'm just being a putz, but for the life of me, I can't find it in the docs or the Wiki.


Azathoth(Posted 2006) [#2]
Function InitArray(A:SomeType[] Var, Sz:Int Var)
   Local Size=Getsize() ' FUNCTION SOMEWHERE ELSE
   A=New SomeType[Size]
   Sz=Size
End Function



Gabriel(Posted 2006) [#3]
Doh.. don't I feel daft. Thanks for that.