Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

passing an array with more dimensions to a function

$
0
0
So I am trying to make a Tic Tac Toe Game, but I kind of got stuck at passing an array with 2-dimensions.
[ autoit ]         
#include #include #include #include #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Tic Tac Toe", 186, 201, 192, 124) $A11 = GUICtrlCreateButton("", 16, 24, 25, 25) $A12 = GUICtrlCreateButton("", 61, 24, 25, 25) $A13 = GUICtrlCreateButton("", 100, 24, 25, 25) $A21 = GUICtrlCreateButton("", 16, 66, 25, 25) $A22 = GUICtrlCreateButton("", 61, 66, 25, 25) $A23 = GUICtrlCreateButton("", 100, 66, 25, 25) $A31 = GUICtrlCreateButton("", 16, 118, 25, 25) $A32 = GUICtrlCreateButton("", 61, 118, 25, 25) $A33 = GUICtrlCreateButton("", 100, 118, 25, 25) $Reset = GUICtrlCreateButton("Reset", 16, 168, 75, 25) $Label1 = GUICtrlCreateLabel("Score:", 144, 8, 35, 17) $Label2 = GUICtrlCreateLabel("X:", 152, 24, 14, 17) $Label3 = GUICtrlCreateLabel("O:", 152, 40, 15, 17) $Xscore = GUICtrlCreateLabel("0", 168, 24, 10, 17) $Oscore = GUICtrlCreateLabel("0", 168, 40, 10, 17) $NewGame = GUICtrlCreateButton("New Game", 96, 168, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### $Turn = 1 #region Button Array Global $ButtonArray[4][4] ;TOP row $ButtonArray[1][1] = $A11 $ButtonArray[1][2] = $A12 $ButtonArray[1][3] = $A13 ;MIDDLE row $ButtonArray[2][1] = $A21 $ButtonArray[2][2] = $A22 $ButtonArray[2][3] = $A23 ;BOTTOM row $ButtonArray[3][1] = $A31 $ButtonArray[3][2] = $A32 $ButtonArray[3][3] = $A33 #endregion Button Array While 1     $nMsg = GUIGetMsg()     Switch $nMsg         Case $GUI_EVENT_CLOSE             Exit         Case $A11             XorO($Turn,$ButtonArray[1][1])     EndSwitch WEnd Func XorO($Turn,ByRef $Btn)     Local $array[$x][$y] = $Btn     Switch $x         Case 1             $XorO_X = 16         Case 2             $XorO_X = 61         Case 3             $XorO_X = 100     EndSwitch     Switch $y         Case 1             $XorO_Y = 24         Case 2             $XorO_Y = 66         Case 3             $XorO_Y = 118     EndSwitch     If Mod($Turn,2) = 1 Then         GUICtrlDelete($Btn)         GUICtrlCreateLabel("X", $XorO_X,$XorO_Y)     Else         GUICtrlDelete($Btn)         GUICtrlCreateLabel("O", $XorO_X,$XorO_Y)     EndIf     $Turn += 1 EndFunc

Basically I want to use the location of the $ButtonArray to use it in the array which would then specify the Location of the "X" or "O".

It would be great if some one can explain how to send an Array with more dimensions into a function. And how to declare a function with an Array of multiply dimensions.

Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>