Touch Posted April 7, 2008 Share Posted April 7, 2008 I am joining in on the game making but it is for my family. I am trying to make a tic-tac-toe game. I was trying to make a 3x3 grid for the buttons. I tried: #include <GUIConstants.au3> Global $Btn[3][3] $GUI = GUICreate("Tic-Tac-Toe", 300, 200) For $i = 1 to 3 For $j = 1 to 3 $Btn[$i][$j] = GUICtrlCreateButton("", 10 + $i, 10 + $j) Next Next GUISetState() While 1 $iMsg = GuiGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd But I keep getting an error: Array variable has incorrect number of subscripts or subscript dimension range exceeded.: $Btn[$i][$j] = GUICtrlCreateButton("", 10 + $i, 10 + $j) ^ ERROR I need to make an equal spacing of 10 between each button. Thanks [center][font="Arial"]If practise makes perfect and no-ones perfect whats the point of practise?[/font]Sorry for my rude attitude when I started here.[/center] Link to comment Share on other sites More sharing options...
weaponx Posted April 7, 2008 Share Posted April 7, 2008 Maybe take a look at some of the existing versions of Tic Tac Toe:http://www.autoitscript.com/forum/index.ph...l=tic++tac++toehttp://www.autoitscript.com/forum/index.ph...l=tic++tac++toehttp://www.autoitscript.com/forum/index.ph...l=tic++tac++toehttp://www.autoitscript.com/forum/index.ph...l=tic++tac++toe Link to comment Share on other sites More sharing options...
Touch Posted April 7, 2008 Author Share Posted April 7, 2008 I fixed it. I figured that I had screwed up my array limit. I fixed this problem: #include <GUIConstants.au3> Global $Btn[3][3] $GUI = GUICreate("Tic-Tac-Toe", 300, 200) For $i = 0 to 2 For $j = 0 to 2 $Btn[$i][$j] = GUICtrlCreateButton("", 10 + $i, 10 + $j) Next Next GUISetState() While 1 $iMsg = GuiGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd But how do I seperate my buttons? [center][font="Arial"]If practise makes perfect and no-ones perfect whats the point of practise?[/font]Sorry for my rude attitude when I started here.[/center] Link to comment Share on other sites More sharing options...
Touch Posted April 7, 2008 Author Share Posted April 7, 2008 I found them before hand But they all use seperatley made buttons. I want to dynamically create my buttons in a loop. [center][font="Arial"]If practise makes perfect and no-ones perfect whats the point of practise?[/font]Sorry for my rude attitude when I started here.[/center] Link to comment Share on other sites More sharing options...
Touch Posted April 7, 2008 Author Share Posted April 7, 2008 Nevermind I just did it For $Y = 0 to 2 For $X = 0 to 2 $btn[$num] = GUICtrlCreateButton ( $num + 1, ($X * 40) + 10, ($Y * 40) + 10, 40, 40) $num += 1 Next Next [center][font="Arial"]If practise makes perfect and no-ones perfect whats the point of practise?[/font]Sorry for my rude attitude when I started here.[/center] Link to comment Share on other sites More sharing options...
SandelPerieanu Posted April 8, 2008 Share Posted April 8, 2008 Simple version: Opt('GUIOnEventMode', 1) #include <GUIConstants.au3> Global $btn[3][3] Global $char = 0 $gui = GUICreate("Tic-Tac-Toe", 150, 150) GUISetOnEvent($gui_event_close, 'Finish') For $i = 0 To 2 For $j = 0 To 2 $btn[$i][$j] = GUICtrlCreateButton("", $i * 50, $j * 50, 50, 50) GUICtrlSetOnEvent(-1, 'SetChar') Next Next GUISetState() While 1 Sleep(1) WEnd Func Finish() GUIDelete($gui) Exit 0 EndFunc ;==>Finish Func SetChar() $button = @GUI_CtrlId $char = Not $char Select Case $char GUICtrlSetData($button, 'X') GUICtrlSetFont($button, 15) Case Else GUICtrlSetData($button, '0') GUICtrlSetFont($button, 15) EndSelect EndFunc ;==>SetChar Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now