CyNDeR Posted November 6, 2007 Posted November 6, 2007 I'm trying to make a small game, to learn about using a GUI and eveything but, i'm kinda stuck, i have the GUI setup, but i'm not sure how to make the diffrent elements of it interact with each other. My code so far: #include <GUIConstants.au3> GUICreate("Guess the Number!", 300, 150, -1, -1) ;Create the GUI GUISetState() GUICtrlCreateLabel("Pick a number between 1 and 20.", 70, 10, 160, 20) ;Instructions $Guess = GUICtrlCreateInput("", 130, 30, 20, 20) ;Input the guess $SubmitGuess = GUICtrlCreateButton("Guess!", 90, 60, 110, 20) ;Button to guess number $Result = GUICtrlCreateInput("", 50, 90, 190, 50) ;Result of the guess. IE: Right or Wrong, etc. $Number = Random(1, 20, 1) ;Create a random number between 1 and 20 While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then Exit EndIf WEnd As you can see, i have most everything in place, just not sure how to do the operations with it. I know how to do this game with popup boxes, but just not with a GUI. My scripts: Random Painter
smashly Posted November 6, 2007 Posted November 6, 2007 Hi,#include <GUIConstants.au3> GUICreate("Guess the Number!", 300, 150, -1, -1) ;Create the GUI GUISetState() GUICtrlCreateLabel("Pick a number between 1 and 20.", 70, 10, 160, 20) ;Instructions $Guess = GUICtrlCreateInput("", 130, 30, 20, 20) ;Input the guess $SubmitGuess = GUICtrlCreateButton("Guess!", 90, 60, 110, 20) ;Button to guess number $Result = GUICtrlCreateInput("", 50, 90, 190, 50, $ES_MULTILINE) ;Result of the guess. IE: Right or Wrong, etc. While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $SubmitGuess $Number = Random(1, 20, 1) ;Create a random number between 1 and 20 If GUICtrlRead($Guess) <> $Number Then GUICtrlSetData($Result, "Wrong Guess!" & @CRLF & "Number Was: " & $Number) Else GUICtrlSetData($Result, "Right Guess!" & @CRLF & "Number Was: " & $Number) EndIf EndSwitch WEnd Cheers
CyNDeR Posted November 6, 2007 Author Posted November 6, 2007 Ah, thanks alot. My internet was down for awhile and i wrote it like this: #include <GUIConstants.au3> GUICreate("Guess the Number!", 300, 150, -1, -1) ;Create the GUI GUISetState() GUICtrlCreateLabel("Pick a number between 1 and 20.", 70, 10, 160, 20) ;Instructions $Guess = GUICtrlCreateInput("", 130, 30, 20, 20) ;Input the guess $SubmitGuess = GUICtrlCreateButton("Guess!", 90, 60, 110, 20) ;Button to guess number $Result = GUICtrlCreateInput("Created by CyNDeR", 50, 90, 190, 50) ;Result of the guess. IE: Right or Wrong, etc. $Number = Random(1, 20, 1) ;Create a random number between 1 and 20 While 1 $msg = GUIGetMsg() Select Case $msg = $SubmitGuess If $Guess = $Number Then $Result = GUICtrlCreateInput("Correct!!", 50, 90, 190, 50) Else $Result = GUICtrlCreateInput("I'm sorry, the answer was: " & $Number, 50, 90, 190, 50) EndIf EndSelect WEnd But, as you can see, my version was only good for 1 guess, not to mention it was really sloppy, lol. Thanks. My scripts: Random Painter
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