Ooops
September 20, 2021, 06:22:47

### Author Topic: [bmx] Send Multi-Dimensional Arrays to a Function by Chroma [ 1+ years ago ]  (Read 822 times)

#### BlitzBot

• Jr. Member
• Posts: 1
##### [bmx] Send Multi-Dimensional Arrays to a Function by Chroma [ 1+ years ago ]
« on: June 29, 2017, 00:28:42 »
Title : Send Multi-Dimensional Arrays to a Function
Author : Chroma
Posted : 1+ years ago

Description : Does what the title says. -)

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
1. Print
2.
3. 'Make array1 and fill it with values
4. Local array1:Int[2,2]
5. For b=0 To 1
6.         For a=0 To 1
7.                 array1[a,b]=a
8.                 Print "array1 "+a+","+b+" = "+array1[a,b]
9.         Next
10. Next
11. Print
12.
13. 'Make array2
14. Local array2:Int[,]
15.
16. 'Pass array1 to the function and get array1 back and put it in array2
17. array2 = ArrayFunc(array1)
18.
19. 'Show the results
20. Print
21. For b=0 To 1
22.         For a = 0 To 1
23.                 Print "Back From ArrayFunc "+a+","+b+" = "+array2[a,b]
24.         Next
25. Next
26.
27. End
28.
29.
30.
31. Function ArrayFunc[,](this:Int[,])
32.         For b=0 To this.length/2-1
33.                 For a=0 To this.length/2-1
34.                         Print "Inside ArrayFunc "+a+","+b+" = "+this[a,b]
35.                         this[a,b]:+5
36.                 Next
37.         Next
38.         Return this
39. End Function