Pouyan Posted October 12, 2020 Posted October 12, 2020 #include <GUIConstantsEx.au3> AutoItSetOption( "MustDeclareVars", 0) Global $idMsg, $button[8][8],$i,$j Local $gui = GUICreate( "Board Game", 700, 700) GUISetState(@SW_SHOW) GUISetOnEvent($GUI_EVENT_CLOSE, "Exitt") For $i = 0 To 7 For $j = 0 To 7 $button[$i][$j] = GUICtrlCreateButton("", 448-56*$i,448-56*$j,56,56) Next Next While 1 $idMsg = GUIGetMsg() Select Case $idMsg = $button[$i][$j] GUICtrlSetState($msg,128) Case $idMsg = $GUI_EVENT_CLOSE Exit 0 EndSelect Sleep(10) WEnd Hello, this is my first time posting in forum yet I was trying to make a game with autoit and this is my code. How can I understand what button just hitted ? I saw checkers post by someone in forum but I couldnt understand it. (15) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: Case $idMsg = $button[$i][$j] Case $idMsg = ^ ERROR
Developers Jos Posted October 12, 2020 Developers Posted October 12, 2020 What do you think the values of $i and $j are at that point? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Pouyan Posted October 13, 2020 Author Posted October 13, 2020 20 hours ago, Jos said: What do you think the values of $i and $j are at that point? $i = 0 to 7 and $j = 0 to 7
Developers Jos Posted October 13, 2020 Developers Posted October 13, 2020 Don't think so as you can see in a Tidied version: #include <GUIConstantsEx.au3> AutoItSetOption("MustDeclareVars", 0) Global $idMsg, $button[8][8], $i, $j Local $gui = GUICreate("Board Game", 700, 700) GUISetState(@SW_SHOW) GUISetOnEvent($GUI_EVENT_CLOSE, "Exitt") For $i = 0 To 7 For $j = 0 To 7 $button[$i][$j] = GUICtrlCreateButton("", 448 - 56 * $i, 448 - 56 * $j, 56, 56) Next Next While 1 $idMsg = GUIGetMsg() Select Case $idMsg = $button[$i][$j] GUICtrlSetState($msg, 128) Case $idMsg = $GUI_EVENT_CLOSE Exit 0 EndSelect Sleep(10) WEnd So my guess is they are both set to 8..... This posted script has other errors too. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Pouyan Posted October 13, 2020 Author Posted October 13, 2020 how can i solve it like I don't want to put 64 diffrent cases there how can I use something like this ?
Developers Jos Posted October 13, 2020 Developers Posted October 13, 2020 You will have to do the same 2 for..next loops in the while loop. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Dan_555 Posted October 13, 2020 Posted October 13, 2020 (edited) Simply loop through the array in this way: $idMsg = GUIGetMsg() For $i = 0 To 7 For $j = 0 To 7 if $idMsg=$button[$i][$j] then ConsoleWrite("button pressed" & @crlf) ExitLoop 2 EndIf Next Next Edited October 13, 2020 by Dan_555 Some of my script sourcecode
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