Sign in to follow this  
Followers 0
JuggaloZeke

(newbie) Reseting Checkboxes?

3 posts in this topic

I use AutoIt a lot for simple tasks that can be automated and I've never attempted to make a GUI before this point. A friend asked me, since I'm "the computer guy," to make a program for a game she plays to help her keep track of what has happened.

It's a simple game where you and your oppenent each have 6 different "weights." These weights are rated 1 through 6, 6 being the heaviest. The computer puts out a random weight and then the players pick one and whoever tips the scale towards themselves wins. The player with the most weights in the end is the winner, problem is she cannot remember what her opponent uses so she asked for a simple program to keep track of what the computer used and what her opponent used.

After reading everything I could from the help file and scanning the forums I still cannot figure out how to get my checkboxes to reset at the press of a button. It's probably something simple but I just can't see it or figure it out. Anyway, onto the code:

#include <GUIConstants.au3>

;;;;;   Options
Opt("GUIOnEventMode", 1)

;;;;;    GUI Create/Title Bar Functions
$moola=GUICreate("Moola", 130, 200, 700, 350, -1, $WS_EX_TOPMOST)
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")

;;;;;    Label -Computer-
GUICtrlCreateLabel("Computer",10,10,50)

;;;;;    Check Boxes -Computer-
$com1=GUICtrlCreateCheckbox("1", 20, 30, 30, 20)
$com2=GUICtrlCreateCheckbox("2", 20, 50, 30, 20)
$com3=GUICtrlCreateCheckbox("3", 20, 70, 30, 20)
$com4=GUICtrlCreateCheckbox("4", 20, 90, 30, 20)
$com5=GUICtrlCreateCheckbox("5", 20, 110, 30, 20)
$com6=GUICtrlCreateCheckbox("6", 20, 130, 30, 20)

;;;;;    Label -Opponent-
GUICtrlCreateLabel("Opponent",75,10,50)

;;;;;   Check Boxes -Opponent-
$opp1=GUICtrlCreateCheckbox("1", 85, 30, 30, 20)
$opp2=GUICtrlCreateCheckbox("2", 85, 50, 30, 20)
$opp3=GUICtrlCreateCheckbox("3", 85, 70, 30, 20)
$opp4=GUICtrlCreateCheckbox("4", 85, 90, 30, 20)
$opp5=GUICtrlCreateCheckbox("5", 85, 110, 30, 20)
$opp6=GUICtrlCreateCheckbox("6", 85, 130, 30, 20)

;;;;;    Reset Button
$reset=GUICtrlCreateButton("Reset", 35, 160, 60)
GUICtrlSetState($com1, $GUI_UNCHECKED)

GUISetState(@SW_SHOW)

While 1
Sleep(500)
Wend

;;;;;   Functions
Func Reset()
       $com1=$GUI_UNCHECKED
       $com2=$GUI_UNCHECKED
       $com3=$GUI_UNCHECKED
       $com4=$GUI_UNCHECKED
       $com5=$GUI_UNCHECKED
       $com6=$GUI_UNCHECKED
       $opp1=$GUI_UNCHECKED
       $opp2=$GUI_UNCHECKED
       $opp3=$GUI_UNCHECKED
       $opp4=$GUI_UNCHECKED
       $opp5=$GUI_UNCHECKED
       $opp6=$GUI_UNCHECKED
EndFunc

Func SpecialEvents()
    Select
        Case @GUI_CTRLID=$GUI_EVENT_CLOSE
            Exit
        Case @GUI_CTRLID=$GUI_EVENT_MINIMIZE
        Case @GUI_CTRLID=$GUI_EVENT_RESTORE
    EndSelect
EndFunc

It's probably sloppy and there's probably unnecessary stuff but like I said, I use AutoIt to automate simple tasks. Thanks to anyone who helps me out.

Share this post


Link to post
Share on other sites



#include <GUIConstants.au3>

;;;;;   Options
Opt("GUIOnEventMode", 1)

;;;;;    GUI Create/Title Bar Functions
$moola=GUICreate("Moola", 130, 200, 700, 350, -1, $WS_EX_TOPMOST)
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")

;;;;;    Label -Computer-
GUICtrlCreateLabel("Computer",10,10,50)

;;;;;    Check Boxes -Computer-
$com1=GUICtrlCreateCheckbox("1", 20, 30, 30, 20)
$com2=GUICtrlCreateCheckbox("2", 20, 50, 30, 20)
$com3=GUICtrlCreateCheckbox("3", 20, 70, 30, 20)
$com4=GUICtrlCreateCheckbox("4", 20, 90, 30, 20)
$com5=GUICtrlCreateCheckbox("5", 20, 110, 30, 20)
$com6=GUICtrlCreateCheckbox("6", 20, 130, 30, 20)
GUICtrlSetState($com1, $GUI_CHECKED)
;;;;;    Label -Opponent-
GUICtrlCreateLabel("Opponent",75,10,50)

;;;;;   Check Boxes -Opponent-
$opp1=GUICtrlCreateCheckbox("1", 85, 30, 30, 20)
$opp2=GUICtrlCreateCheckbox("2", 85, 50, 30, 20)
$opp3=GUICtrlCreateCheckbox("3", 85, 70, 30, 20)
$opp4=GUICtrlCreateCheckbox("4", 85, 90, 30, 20)
$opp5=GUICtrlCreateCheckbox("5", 85, 110, 30, 20)
$opp6=GUICtrlCreateCheckbox("6", 85, 130, 30, 20)

;;;;;    Reset Button
$reset=GUICtrlCreateButton("Reset", 35, 160, 60)
GUICtrlSetOnEvent( -1, "Reset")

GUISetState(@SW_SHOW)

While 1
Sleep(500)
Wend

;;;;;   Functions
Func Reset()
      GUICtrlSetState($com1, $GUI_CHECKED)
      GUICtrlSetState($com2, $GUI_UNCHECKED)
      GUICtrlSetState($com3, $GUI_UNCHECKED)
      GUICtrlSetState($com4, $GUI_UNCHECKED)
      GUICtrlSetState($com5, $GUI_UNCHECKED)
      GUICtrlSetState($com6, $GUI_UNCHECKED)
       GUICtrlSetState($opp1, $GUI_CHECKED)
       GUICtrlSetState($opp2, $GUI_UNCHECKED)
       GUICtrlSetState($opp3, $GUI_UNCHECKED)
       GUICtrlSetState($opp4, $GUI_UNCHECKED)
       GUICtrlSetState($opp5, $GUI_UNCHECKED)
       GUICtrlSetState($opp6, $GUI_UNCHECKED)
EndFunc

Func SpecialEvents()
    Select
        Case @GUI_CTRLID=$GUI_EVENT_CLOSE
            Exit
        Case @GUI_CTRLID=$GUI_EVENT_MINIMIZE
        Case @GUI_CTRLID=$GUI_EVENT_RESTORE
    EndSelect
EndFunc

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

I had that GUICtrlSetStateOnEvent in there is some form but I couldn't get it to work either but I see what I was doing wrong now. Thanks!

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0