greggklein Posted April 4, 2008 Posted April 4, 2008 I would like to update a window with a new problem an update counter for correct and missed problems without deleting window and then creating another. I would like a smooth transition. If you could run the following code, you'll see what I mean about the non smooth transition with a new window create each time. Sorry I am a newbie: #include <GUIConstants.au3> $a = InputBox("How many questions","How many questions would you like to try?") $m = InputBox("Max Number","WHAT IS THE BIGGEST NUMBER THAT YOU WANT TO ADD?") $c = 0 $w = 0 $j = 0 While $c<$a $x = Round(Random(0,$m)) $y = Round(Random(0,$m)) $font = "Comic Sans MS" GUICreate("ADD THESE NUMBERS", 500,300, -1, -1) GUISetBkColor(16777215) GUICtrlCreatePic(@WorkingDir&"\images\main\correct.bmp",5,5,16,16) GUICtrlCreatePic(@WorkingDir&"\images\main\false.bmp",5,30,16,16) GUICtrlCreateLabel($w,25,5) GUICtrlCreateLabel($j,25,30) $k = GUICtrlCreateInput("",235,200,100,20) $btn = GUICtrlCreateButton("CHECK ANSWER",125,200,100,20) GUICtrlSetState($btn, $GUI_FOCUS) Send(@TAB) GUISetFont (72, 400, -1, $font) GUICtrlCreateLabel($x&" + "&$y,125,50,400) GUISetState () $msg = 0 While $msg <> $GUI_EVENT_CLOSE $msg = GUIGetMsg() Select Case $msg = $btn ExitLoop EndSelect Wend If GUICtrlRead($k) = $x+$y Then SoundPlay(@WorkingDir&"\sounds\RING.wav",0) $w = $w+1 EndIf If GUICtrlRead($k) <> $x+$y Then SoundPlay(@WorkingDir&"\sounds\BUZZ2.wav",0) MsgBox(0,"REMEMBER!!", $x & " + " & $y & " = " & $x+$y & " not " & GUICtrlRead($k)) $j = $j+1 EndIf GUIDelete() $c = $c+1 WEnd MsgBox(0,"# CORRECT","You got " & $w & " out of " & $a & " correct!")
Achilles Posted April 4, 2008 Posted April 4, 2008 expandcollapse popup#include <GUIConstants.au3> $numberQuestions = InputBox("How many questions", "How many questions would you like to try?") $max = InputBox("Max Number", "WHAT IS THE BIGGEST NUMBER THAT YOU WANT TO ADD?") $questionsAsked = 0 $right = 0 $wrong = 0 $font = "Comic Sans MS" GUICreate("ADD THESE NUMBERS", 500, 300, -1, -1) GUISetBkColor(16777215) GUICtrlCreatePic(@WorkingDir & "\images\main\correct.bmp", 5, 5, 16, 16) GUICtrlCreatePic(@WorkingDir & "\images\main\false.bmp", 5, 30, 16, 16) $lblRight = GUICtrlCreateLabel('Right: ' & $right, 25, 5) $lblWrong = GUICtrlCreateLabel('Wrong: ' & $wrong, 25, 30) $txtUserAnswer = GUICtrlCreateInput("", 235, 200, 100, 20) $btn = GUICtrlCreateButton("CHECK ANSWER", 125, 200, 100, 20) GUICtrlSetState($btn, $GUI_FOCUS) Send(@TAB) GUISetFont(72, 400, -1, $font) $x = Random(0, $max, 1); The Round() was not needed, just add the last 1 $y = Random(0, $max, 1) GUICtrlCreateLabel($x & " + " & $y, 125, 50, 400) GUISetState() While $questionsAsked < $numberQuestions $msg = GUIGetMsg() Select Case $msg = $btn If GUICtrlRead($txtUserAnswer) = $x + $y Then SoundPlay(@WorkingDir & "\sounds\RING.wav", 0) $right += 1 GuiCtrlSetData($lblRight, 'Right: ' & $right) Else SoundPlay(@WorkingDir & "\sounds\BUZZ2.wav", 0) MsgBox(0, "REMEMBER!!", $x & " + " & $y & " = " & $x + $y & " not " & GUICtrlRead($txtUserAnswer)) $wrong += 1 GuiCtrlSetData($lblWrong, 'Wrong: ' & $wrong) EndIf $questionsAsked += 1 If $questionsAsked < $numberQuestions then $x = Random(0, $max, 1); The Round() was not needed, just add the last 1 $y = Random(0, $max, 1) GUICtrlCreateLabel($x & " + " & $y, 125, 50, 400) EndIf Case $msg = $GUI_EVENT_CLOSE Exit EndSelect Wend MsgBox(0, "# CORRECT", "You got " & $right & " out of " & $questionsAsked & " correct!")I made lots of changes... However, the biggest one is that I renamed most of your variables. It really helps to make variable names descriptive, not just things like $j and $m. Ask if you don't understand anything that goes on in this code. My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
greggklein Posted April 4, 2008 Author Posted April 4, 2008 Thanks I did add GuiCtrlSetData($txtUserAnswer, "") at the bottom because input field was not returning blank Thanks again
greggklein Posted April 4, 2008 Author Posted April 4, 2008 If I wanted to update a picture in window instead what should I enetr? Thanks for your help here is the code #include <GUIConstants.au3> WinClose("CHOOSE A GAME TO PLAY") $numberQuestions = InputBox("How many questions", "How many questions would you like to try?") $max = InputBox("Max Number", "WHAT IS THE LARGEST NUMBER OF COINS THAT YOU WANT TO ADD?") $questionsAsked = 0 $right = 0 $wrong = 0 $font = "Comic Sans MS" GUICreate("HOW MUCH MONEY?", 700, 402, -1, -1) GUISetBkColor(16777215) GUICtrlCreatePic(@WorkingDir&"\images\main\correct.bmp",5,286,16,16) GUICtrlCreatePic(@WorkingDir&"\images\main\false.bmp",5,311,16,16) $lblRight = GUICtrlCreateLabel($right, 25, 286) $lblWrong = GUICtrlCreateLabel($wrong, 25, 311) $btn = GUICtrlCreateButton("CHECK ANSWER",240,350,100,20) $txtUserAnswer = GUICtrlCreateInput("",135,350,100,20) GUICtrlSetState($btn, $GUI_FOCUS) Send(@TAB) GUISetFont(72, 400, -1, $font) $money = Random(1,$max,1) $pic = GUICtrlCreatePic (@WorkingDir&"\images\money\"&$money&".gif",0,0,700,281) GUISetState() While $questionsAsked < $numberQuestions $msg = GUIGetMsg() Select Case $msg = $btn If GUICtrlRead($txtUserAnswer) = $money Then SoundPlay(@WorkingDir & "\sounds\RING.wav", 0) $right += 1 GuiCtrlSetData($lblRight,$right) Else SoundPlay(@WorkingDir & "\sounds\BUZZ2.wav", 0) MsgBox(0, "INCORRECT!", "There is "&$money& " cents not " & GUICtrlRead($txtUserAnswer)) $wrong += 1 GuiCtrlSetData($lblWrong,$wrong) EndIf $questionsAsked += 1 GuiCtrlSetData($txtUserAnswer, "") GUICtrlSetState($btn, $GUI_FOCUS) Send(@TAB) If $questionsAsked < $numberQuestions Then $money = Random(1,$max,1) GuiCtrlSetData($pic, ????????????????????????) EndIf Case $msg = $GUI_EVENT_CLOSE Exit EndSelect Wend MsgBox(0, "# CORRECT", "You got " & $right & " out of " & $questionsAsked & " correct!") Run("games.exe")
greggklein Posted April 4, 2008 Author Posted April 4, 2008 If $questionsAsked < $numberQuestions Then $money = Random(1,$max,1) GUICtrlCreatePic (@WorkingDir&"\images\money\"&$money&".gif",0,0,700,281) almost works it puts image in 1 step too late
greggklein Posted April 4, 2008 Author Posted April 4, 2008 I figured it out If $questionsAsked < $numberQuestions Then $money = Random(1,$max,1) GUICtrlDelete($pic) $pic = GUICtrlCreatePic (@WorkingDir&"\images\money\"&$money&".gif",0,0,700,281) EndIf I just deleted pic and then redefined it
Achilles Posted April 5, 2008 Posted April 5, 2008 Look at GuiCtrlSetImage() My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
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