how do I pass an array name to a function?
Blitz3D Forums/Blitz3D Beginners Area/how do I pass an array name to a function?
| ||
Ok,... I've got a function to do bilinear interpolation on an array, but I don't know how to pass the array name to the function. In the example below, I have it hard coded to the array "grid" I would like to be able to specify that name when I call the function if possible. for example,... BilinearInterpValue2# ( x1# , y1# , arrayname$) Function BilinearInterpValue2# ( x1# , y1# ) X_low = Int ( Floor(x1) ) X_hi = Int ( Ceil (x1) ) Y_low = Int ( Floor(y1) ) Y_hi = Int ( Ceil (y1) ) x_per# = x1 - x_low y_per# = y1 - y_low p00 = grid ( x_low , y_low ) p10 = grid ( x_hi , y_low ) p01 = grid ( x_low , y_hi ) p11 = grid ( x_hi , y_hi ) i1 = p00 + (p10 - p00) * x_per i2 = p01 + (p11 - p01) * x_per Return i1 + (i2-i1) * y_per End Function |
| ||
This is an unfortunate limitation of Blitz3D. There is another kind of array, denoted with a[ ] rather than a( ). This can be passed to a function. However, such arrays are one dimensional. So you are stuck with the hard coded approach. |
| ||
[] arrays are one-dimensional, but there are ways to fake multidimensional arrays with one-dimensional arrays. You'll probably have to use something like this : Function GetPosition (x,y,ym) Return x*ym+y End Function Instance\Array[GetPosition(xpos,ypos,ymaxpos)] For getting the size of the one-dimensional array for initializing, I think you'll have to use xmaxpos*ymaxpos. Never tried using something like this before, so I'm not 100% sure it would work. |
| ||
Since arrays are global, why would you need to pass them to an function? You can access arrays from inside a function anyway. |
| ||
Because he wants his function to work on multiple arrays maybe? |
| ||
yes,... that was what I wanted to be able to do. I don't really need it for this current code, but I wanted to make the function something that was self-contained rather than having to hard code the proper array into it. Thanks for the answers btw. |