[bmx] Send Multi-Dimensional Arrays to a Function by Chroma [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:42

Previous topic - Next topic

BlitzBot

Title : Send Multi-Dimensional Arrays to a Function
Author : Chroma
Posted : 1+ years ago

Description : Does what the title says. :o-)

You can increase the number of dimensions by adding commas to brackets ie. [,,,].  Just remember to make them all match up.

Btw, thanks goes to Perturbatio, Azazoth, YouCanCode, and Tom Darby for helping me work this out.  Thanks guys...hugs and kisses. Teehee.


Code :
Code (blitzmax) Select
Print

'Make array1 and fill it with values
Local array1:Int[2,2]
For b=0 To 1
For a=0 To 1
array1[a,b]=a
Print "array1 "+a+","+b+" = "+array1[a,b]
Next
Next
Print

'Make array2
Local array2:Int[,]

'Pass array1 to the function and get array1 back and put it in array2
array2 = ArrayFunc(array1)

'Show the results
Print
For b=0 To 1
For a = 0 To 1
Print "Back From ArrayFunc "+a+","+b+" = "+array2[a,b]
Next
Next

End



Function ArrayFunc[,](this:Int[,])
For b=0 To this.length/2-1
For a=0 To this.length/2-1
Print "Inside ArrayFunc "+a+","+b+" = "+this[a,b]
this[a,b]:+5
Next
Next
Return this
End Function


Comments : none...