Topher Posted April 19, 2012 Share Posted April 19, 2012 Well, I'm right at the beginning of a project and already missing the obvious (I hope) This creates a square of 9 x 9 pushbuttons. The routine for registering whether one of the buttons has been pressed is not working. (I've left out a couple of lengthy irrelevant routines but the idea is here) expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #Include <Misc.au3> #include <WindowsConstants.au3> Global Const $Tribe = 1 Global Const $Clan = 2 Global Const $HunterN = 3 Global Const $HunterS = 4 Global Const $HunterE = 5 Global Const $HunterW = 6 Global Const $HunterNE = 7 Global Const $HunterNW = 8 Global Const $HunterSE = 9 Global Const $HunterSW = 10 Global Const $Red = 0 Global Const $Green = 100 Global Const $Black = 0 ; no action Global Const $Yellow = 1 ; selected Global Const $Cyan = 2 ; option Dim $Board[9][9] Dim $hBoard[9][9] Dim $Color[9][9] Dim $hColor[9][9] $hGUI = GUICreate("IX ver 0.01", 68 * 9 + 300, 68 * 9) InitializeBoard() GUISetState() DrawBoard() ; the main loop While True $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then OnExit() EndIf For $side = 0 to 8 For $fore = 0 to 8 If $msg = $hBoard[$fore][$side] Then $Color[$fore][$side] = $Yellow DrawBoard() EndIf Next Next Sleep(25) WEnd Func OnExit() GUIDelete($hGUI) Exit EndFunc Func WipeColor() For $x = 0 to 8 For $y = 0 to 8 $Color[$x][$y] = 0 Next Next DrawBoard() EndFunc Func DrawBoard() GUISetState(@SW_LOCK) For $x = 0 to 8 For $y = 0 to 8 GUICtrlSetImage ( $hColor[$x][$y], ColorName($Color[$x][$y])) GUICtrlSetImage ( $hBoard[$x][$y], PieceName($Board[$x][$y])) Next Next GUISetState(@SW_UNLOCK) EndFunc ; create the board picture handles ; and set all pieces to opening positions Func InitializeBoard() For $x = 0 To 8 For $y = 0 To 8 $Color[$x][$y] = $Black $hColor[$x][$y] = GUICtrlCreatePic(".\Images\Black.bmp", $x * 68 + 150, $y * 68, 68, 68) $Board[$x][$y] = 0 ; empty squares $hBoard[$x][$y] = GUICtrlCreateButton("", $x * 68 + 2 + 150, $y * 68 + 2, 64, 64, BitOR($BS_BITMAP, $BS_FLAT)) Next Next For $x = 1 to 7 Step 2 $Board[0][$x] = $Tribe + $Red $Board[8][$x] = $Tribe + $Green Next EndFunc [left][hr] $mood = "whimsy" $mode = "confused" $randomChaos = True Do Something() Until $Tired[/left][left]Reflex (Arcade game)[/left][left]IX (Board game)[/left][left]The Word Game (Word game)[/left][left]Plastic Sliding Squares Puzzle (Puzzle)[/left] Link to comment Share on other sites More sharing options...
water Posted April 19, 2012 Share Posted April 19, 2012 "is not working"? Could you please be a bit more precise? Does your script crash? Does it act unexpected? Do you get an error message? More information is needed ... My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Topher Posted April 19, 2012 Author Share Posted April 19, 2012 Sorry, it does not register the button click at all. just keeps puttering along as if I had done nothing. [left][hr] $mood = "whimsy" $mode = "confused" $randomChaos = True Do Something() Until $Tired[/left][left]Reflex (Arcade game)[/left][left]IX (Board game)[/left][left]The Word Game (Word game)[/left][left]Plastic Sliding Squares Puzzle (Puzzle)[/left] Link to comment Share on other sites More sharing options...
Xandy Posted April 19, 2012 Share Posted April 19, 2012 (edited) try replacing dim with global on declaration of $hboard[][] or pass the array byref by changing the func InitializeBoard() to func InitializeBoard(byref $hboard) then pass $hboard in the call to InitializeBoardedit: make all of the arrays you're using in InitializeBoard global or pass them all byref to the function, if your changing the values of the arrays and expect to keep the results.Looks good by the way. Let me know if that's not the answer, but it looks like the scope is wrong for the $hboard to be usable. Other than that it looks good.The control graphic will likely be displayed but the control_id or handle would be lost. So you wouldn't be able to click the button. Edited April 19, 2012 by Xandy Human Male Programmer (-_-) Xandy About (^o^) Discord - Xandy Programmer MapIt (Tile world editor, Image Tile Extractor, and Game Maker) Link to comment Share on other sites More sharing options...
water Posted April 19, 2012 Share Posted April 19, 2012 You have stripped down your script a bit too much. Some functions are missing. What we need is a script as small as possible which lets us reproduce the problem you have. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Topher Posted April 19, 2012 Author Share Posted April 19, 2012 (edited) You have stripped down your script a bit too much. Some functions are missing. What we need is a script as small as possible which lets us reproduce the problem you have. All I took out was: expandcollapse popup; return the file name for a given shape Func PieceName($piece) Switch $piece Case 0 $FileName = ".ImagesSquare.bmp" Case 1 $FileName = ".ImagesRed Tribe.bmp" Case 101 $FileName = ".ImagesGreen Tribe.bmp" Case 2 $FileName = ".ImagesRed Clan.bmp" Case 102 $FileName = ".ImagesGreen Clan.bmp" Case 3 $FileName = ".ImagesRed HunterN.bmp" Case 103 $FileName = ".ImagesGreen HunterN.bmp" Case 4 $FileName = ".ImagesRed HunterS.bmp" Case 104 $FileName = ".ImagesGreen HunterS.bmp" Case 5 $FileName = ".ImagesRed HunterE.bmp" Case 105 $FileName = ".ImagesGreen HunterE.bmp" Case 6 $FileName = ".ImagesRed HunterW.bmp" Case 106 $FileName = ".ImagesGreen HunterW.bmp" Case 7 $FileName = ".ImagesRed HunterNE.bmp" Case 107 $FileName = ".ImagesGreen HunterNE.bmp" Case 8 $FileName = ".ImagesRed HunterNW.bmp" Case 108 $FileName = ".ImagesGreen HunterNW.bmp" Case 9 $FileName = ".ImagesRed HunterSE.bmp" Case 109 $FileName = ".ImagesGreen HunterSE.bmp" Case 10 $FileName = ".ImagesRed HunterSW.bmp" Case 110 $FileName = ".ImagesGreen HunterSW.bmp" Case Else MsgBox(0, "Fatal Error","Invalid Piece Number: " & $piece) Exit EndSwitch Return $FileName EndFunc ; return the name of the square color for a given color Func ColorName($setting) Switch $setting Case $Black $FileName =".ImagesBlack.bmp" Case $Yellow $FileName = ".IamgesYellow.bmp" Case $Cyan $FileName = ".IamgesCyan.bmp" Case Else MsgBox(0, "Fatal Error", "Invalid Square Color:" & $setting) Exit EndSwitch Return $FileName EndFunc which relied so much on a bunch of bmps that I figured it to be unusable. Edited April 19, 2012 by Topher [left][hr] $mood = "whimsy" $mode = "confused" $randomChaos = True Do Something() Until $Tired[/left][left]Reflex (Arcade game)[/left][left]IX (Board game)[/left][left]The Word Game (Word game)[/left][left]Plastic Sliding Squares Puzzle (Puzzle)[/left] Link to comment Share on other sites More sharing options...
water Posted April 19, 2012 Share Posted April 19, 2012 InsertMsgBox(0,"", "Side: " & $side & @CRLF & "Fore: " & $fore)afterIf $msg = $hBoard[$fore][$side] Thenand you will see that your script handles clicks on a button. But the pictures don't get changed. Can't test because I don't have the images. But you could try to specify absolute path names. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Topher Posted April 19, 2012 Author Share Posted April 19, 2012 (edited) I had put a beep in there as a test; it never rang.images are loading fine (it initializes just fine) - if I understand what you said.I can zip up the images if that will help. Edited April 19, 2012 by Topher [left][hr] $mood = "whimsy" $mode = "confused" $randomChaos = True Do Something() Until $Tired[/left][left]Reflex (Arcade game)[/left][left]IX (Board game)[/left][left]The Word Game (Word game)[/left][left]Plastic Sliding Squares Puzzle (Puzzle)[/left] Link to comment Share on other sites More sharing options...
water Posted April 19, 2012 Share Posted April 19, 2012 If you like you can post them. Unfortunately I won't be able to test your script today because it's time to go to bed now My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Topher Posted April 19, 2012 Author Share Posted April 19, 2012 Image ZipSleep well, thank you for the fast attention. [left][hr] $mood = "whimsy" $mode = "confused" $randomChaos = True Do Something() Until $Tired[/left][left]Reflex (Arcade game)[/left][left]IX (Board game)[/left][left]The Word Game (Word game)[/left][left]Plastic Sliding Squares Puzzle (Puzzle)[/left] Link to comment Share on other sites More sharing options...
Xandy Posted April 19, 2012 Share Posted April 19, 2012 ".ImagesBlack.bmp" I don't think that forces the root of your script either. The working dir or whatever can change. If you want to force the root script folder, I had to use @scriptdir&"ImagesBlack.bmp". Please provide the pictures. Human Male Programmer (-_-) Xandy About (^o^) Discord - Xandy Programmer MapIt (Tile world editor, Image Tile Extractor, and Game Maker) Link to comment Share on other sites More sharing options...
Topher Posted April 19, 2012 Author Share Posted April 19, 2012 ".ImagesBlack.bmp"I don't think that forces the root of your script either. The working dir or whatever can change.If you want to force the root script folder, I had to use @scriptdir&"ImagesBlack.bmp".Please provide the pictures.I've had success (at least no one complained) with "." but I'll make the more professional change.image zip provided one post back. [left][hr] $mood = "whimsy" $mode = "confused" $randomChaos = True Do Something() Until $Tired[/left][left]Reflex (Arcade game)[/left][left]IX (Board game)[/left][left]The Word Game (Word game)[/left][left]Plastic Sliding Squares Puzzle (Puzzle)[/left] Link to comment Share on other sites More sharing options...
Xandy Posted April 19, 2012 Share Posted April 19, 2012 (edited) solution! add $gui_disable to the creation of $hColor $hColor[$x][$y] = GUICtrlCreatePic(@scriptdir&"ImagesBlack.bmp", $x * 68 + 150, $y * 68, 68, 68, $gui_disable) It was stealing the focus clicks from the buttons. $gui_disable will stop that from happening and now it beeps. Edited April 19, 2012 by Xandy Human Male Programmer (-_-) Xandy About (^o^) Discord - Xandy Programmer MapIt (Tile world editor, Image Tile Extractor, and Game Maker) Link to comment Share on other sites More sharing options...
Topher Posted April 19, 2012 Author Share Posted April 19, 2012 That did it. Thank you. [left][hr] $mood = "whimsy" $mode = "confused" $randomChaos = True Do Something() Until $Tired[/left][left]Reflex (Arcade game)[/left][left]IX (Board game)[/left][left]The Word Game (Word game)[/left][left]Plastic Sliding Squares Puzzle (Puzzle)[/left] Link to comment Share on other sites More sharing options...
Xandy Posted April 19, 2012 Share Posted April 19, 2012 I feel pretty good about it. Glad I could help. Human Male Programmer (-_-) Xandy About (^o^) Discord - Xandy Programmer MapIt (Tile world editor, Image Tile Extractor, and Game Maker) 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