Passing array data via functions

Blitz3D Forums/Blitz3D Beginners Area/Passing array data via functions

gilk(Posted 2006) [#1]
Hi,

I'm a Blitz newbie. I'm trying to pass an array to a function in Blitz3D by reference how can this done?

Thanks,


markcw(Posted 2006) [#2]
you mean like this?
Graphics 640,480,0,2
SetBuffer BackBuffer()

Dim array(10)

array(0)=123456789

test=GetValue(array(0))

While Not KeyHit(1)
 Cls

 Text 0,0,"array(0)="+array(0)+" test="+test

 Flip
Wend

Function GetValue(value)

 Return value

End Function



gilk(Posted 2006) [#3]
Not quite ... acutally I would like the whole array passed to the function (or better yet the reference or address). Currently what you are doing is only passing the first element which is array(0).


Dreamora(Posted 2006) [#4]
References / adresses: not possible. Blitz3D has no references. Only thing to interface with outside that works similar are banks

Arrays: You can use BlitzArrays to achieve that. BlitzArrays have a static size and are declared through
someArr[10] instead of dim and ()

then you can pass them by
Function SomeFunc(arr[])
...
end function



If you want or need more, you will have to use a different language (BlitzMax is capable of that as well, but not blitz3d or blitzplus)


markcw(Posted 2006) [#5]
arrays are global, you just need to dim them outside a function, then refer to them inside a function like this.
Graphics 640,480,0,2
SetBuffer BackBuffer()

Dim array(10)

array(0)=123456789

test=GetValue()

While Not KeyHit(1)
 Cls

 Text 0,0,"array(0)="+array(0)+" test="+test

 Flip
Wend

Function GetValue()

 Return array(0)

End Function



b32(Posted 2006) [#6]
To use banks, try this:



jfk EO-11110(Posted 2006) [#7]
I never tried it but I'm pretty sure the DIM array structure is simple, at least for int and float. I also think the array handle may be a pointer to a structure that describes the array. If this is once hacked, you could tell the function what array you want some way.

I didn't tried it yet though there have been situations when I needed it. However, it wouldn't be a proper solution.


gilk(Posted 2006) [#8]
If someone knows how I can obtain an array handle that would work nicely.

Anyway, for now ... I think I'll go with the bank implementation because the functions that I am calling are from a "included" BB program.

Thanks


mindstorms(Posted 2006) [#9]
It shouldn't matter where the funcitions are...global means anything can get to it, even include files.