Passing arrarys to a function

Blitz3D Forums/Blitz3D Programming/Passing arrarys to a function

Amanda Dearheart(Posted 2012) [#1]
Is it possible to pass arrays to a function?

For example

Dim a(10)

function Thisfun(param())

this value = param(1)

end function

Thisfun(a())

Hopefully, this sloppy code will demonstrate what I mean!


Matty(Posted 2012) [#2]
Arrays are global so I'm not sure there is any need to pass an array to a function?


Floyd(Posted 2012) [#3]
The inability to pass arrays to functions was an unfortunate "feature" of Blitz and is one of the reasons another kind of array was introduced.


There is a very terse introduction buried in the documentation for Dim: http://blitzbasic.com/b3ddocs/command.php?name=dim&ref=goto

These are one dimensional and may not be relevant if you are still working on the Game of Life.


Zethrax(Posted 2012) [#4]
Depending on the type of data you're working with, Banks may be another option. You can create as many as you need (so they're basically instancable) and a Bank handle is an integer, so you can easily pass it to and from a function. Parsing and storing data in a Bank is a much more hands-on affair though, but you can store whatever data you want (you're not limited to a single data type per bank).


Bobysait(Posted 2012) [#5]
You can use the local-fixed-size-arrays form instead (not "Dim")



Local MyArray%[12]
MyArray[1] = 50


Function MyFunction%(Param%[12])
 value = Param[1]
 return value
End Function

Print MyFunction(MyArray)
waitkey
end



Amanda Dearheart(Posted 2012) [#6]
Thanks, all!