nf67 Posted October 2, 2008 Share Posted October 2, 2008 (edited) Hi there, I wanted to make a simple game in which you should press a certain button within a second, after you've pressed it, the program should give you the next button to press ( within one second ). I've created a simple GUI with 3 buttons ( named 1, 2 and 3 ) and encountered some problems with "the program should give you the next button to press". Have a look at my code with the description of my problem in it: #include <GUIConstants.au3> $Beepor = GUICreate("Beepor", 284, 439, 193, 115) $Button1 = GUICtrlCreateButton("1", 15, 360, 80, 60, 0) $Button2 = GUICtrlCreateButton("2", 104, 360, 80, 60, 0) $Button3 = GUICtrlCreateButton("3", 192, 360, 80, 60, 0) $Whattodo = GUICtrlCreateEdit("", 8, 16, 265, 337) GUICtrlSetData(-1, "Press a button!") GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 soundplay ( "./Beep1.wav" ) GUICtrlSetData($Whattodo, '-RANDOMNUMBER-'&@crlf, 1) ;How can I make it insert a random number in $Whattodo ? ;???????? ; How can I make it say WRONG ( in $Whattodo ) if you don't press the number within a second or press a different number than randomly generated one? Case $Button2 soundplay ( "./Beep2.wav" ) GUICtrlSetData($Whattodo, '-RANDOMNUMBER-'&@crlf, 1) ;???????? Case $Button3 soundplay ( "./Beep3.wav" ) GUICtrlSetData($Whattodo, '-RANDOMNUMBER-'&@crlf, 1) ;???????? EndSwitch WEnd Edited October 2, 2008 by nf67 Link to comment Share on other sites More sharing options...
Andreik Posted October 2, 2008 Share Posted October 2, 2008 Use Random() function. Link to comment Share on other sites More sharing options...
nf67 Posted October 2, 2008 Author Share Posted October 2, 2008 Use Random() function. That would be: GUICtrlSetData($Whattodo, Random( 1, 3 ) &@crlf, 1) It works, but it gives a number with a lot of decimals.... I only want 1 2 or 3.. Please help Link to comment Share on other sites More sharing options...
Andreik Posted October 2, 2008 Share Posted October 2, 2008 (edited) That would be: GUICtrlSetData($Whattodo, Random( 1, 3 ) &@crlf, 1) It works, but it gives a number with a lot of decimals.... I only want 1 2 or 3.. Please helpRandom(1,3,1) the last parameter force the function to return an integer. Like this: #include <GUIConstants.au3> $Beepor = GUICreate("Beepor", 284, 439, 193, 115) $Button1 = GUICtrlCreateButton("1", 15, 360, 80, 60, 0) $Button2 = GUICtrlCreateButton("2", 104, 360, 80, 60, 0) $Button3 = GUICtrlCreateButton("3", 192, 360, 80, 60, 0) $Whattodo = GUICtrlCreateEdit("", 8, 16, 265, 337) GUICtrlSetData(-1, "Press a button!"&@CRLF) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 GUICtrlSetData($Whattodo, Random(1,3,1)&@crlf, 1) ;How can I make it insert a random number in $Whattodo ? ;???????? ; How can I make it say WRONG ( in $Whattodo ) if you don't press the number within a second or press a different number than randomly generated one? Case $Button2 GUICtrlSetData($Whattodo, Random(1,3,1)&@crlf, 1) ;???????? Case $Button3 GUICtrlSetData($Whattodo, Random(1,3,1)&@crlf, 1) ;???????? EndSwitch WEnd Edited October 2, 2008 by Andreik Link to comment Share on other sites More sharing options...
nf67 Posted October 2, 2008 Author Share Posted October 2, 2008 Thanks Andreik, but I still have the other problem left, I described it below: Case $Button1 soundplay ( "./Beep1.wav" ) GUICtrlSetData($Whattodo, Random( 1, 3, 1 ) &@crlf, 1) ; Do step 2 and 3, unless the number pressed corresponds with the last number in $Whattodo ( Simplified: DO NOT CONTINUE IF NUMBER CORREPONDS WITH LAST $Whattodo ENTRY ) GUICtrlSetData($Whattodo, "Wrong" &@crlf, 1);Step 2 GUICtrlSetData($Whattodo, Random( 1, 3, 1 ) &@crlf, 1); Step 3 Link to comment Share on other sites More sharing options...
nf67 Posted October 3, 2008 Author Share Posted October 3, 2008 Anyone? Link to comment Share on other sites More sharing options...
Andreik Posted October 3, 2008 Share Posted October 3, 2008 Anyone?Like this? (I`m not a very good english speaker) #include <GUIConstants.au3> Global $LAST = 0 $Beepor = GUICreate("Beepor", 284, 439, 193, 115) $Button1 = GUICtrlCreateButton("1", 15, 360, 80, 60, 0) $Button2 = GUICtrlCreateButton("2", 104, 360, 80, 60, 0) $Button3 = GUICtrlCreateButton("3", 192, 360, 80, 60, 0) $Whattodo = GUICtrlCreateEdit("", 8, 16, 265, 337) GUICtrlSetData(-1, "Press a button!"&@CRLF) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 If $LAST <> 1 Then Soundplay ( "./Beep1.wav" ) GUICtrlSetData($Whattodo, Random(1,3,1)&@crlf, 1) $LAST = 1 EndIf Case $Button2 If $LAST <> 2 Then Soundplay ( "./Beep2.wav" ) GUICtrlSetData($Whattodo, Random(1,3,1)&@crlf, 1) $LAST = 2 EndIf Case $Button3 If $LAST <> 3 Then Soundplay ( "./Beep3.wav" ) GUICtrlSetData($Whattodo, Random(1,3,1)&@crlf, 1) $LAST = 3 EndIf EndSwitch WEnd Link to comment Share on other sites More sharing options...
nf67 Posted October 3, 2008 Author Share Posted October 3, 2008 (edited) Mm that's not really it, it seems like this script locks the button after you've pressed it?If I press 1, I can't press it again until I've pressed a different button._____________________________________________________________________What I need is this:_____________________________________________________________________Timer element needs to be created hereCase $Button 1-check if button = last entry in $Whattodo---if it is NOT: GUICtrlSetData($Whattodo, "WRONG" &@crlf, 1)GUICtrlSetData($Whattodo, Random(1,3,1)&@crlf, 1)Reset timer---if it is: GUICtrlSetData($Whattodo, Random(1,3,1)&@crlf, 1)Reset timer-check if button was pressed within 1 second---if it is NOT: GUICtrlSetData($Whattodo, "WRONG" &@crlf, 1)GUICtrlSetData($Whattodo, Random(1,3,1)&@crlf, 1)Reset timer---if it is: GUICtrlSetData($Whattodo, "WRONG" &@crlf, 1)GUICtrlSetData($Whattodo, Random(1,3,1)&@crlf, 1)Reset timer_____________________________________________________________________Button check elements are italic and underlinedTimer check elements are bold_____________________________________________________________________( Sorry, I'm not a good programmer ) Edited October 3, 2008 by nf67 Link to comment Share on other sites More sharing options...
nf67 Posted October 3, 2008 Author Share Posted October 3, 2008 (edited) I used a bit of your code Andreik and I've made progress But I've encountered yet another problem. I need two randoms to be equal. They should be random, but equal to eachother, like Random1=Random2. Here's the code: expandcollapse popup#include <GUIConstants.au3> Global $LAST = 1 $Beepor = GUICreate("Beepor", 284, 439, 193, 115) $Button1 = GUICtrlCreateButton("1", 15, 360, 80, 60, 0) $Button2 = GUICtrlCreateButton("2", 104, 360, 80, 60, 0) $Button3 = GUICtrlCreateButton("3", 192, 360, 80, 60, 0) $Whattodo = GUICtrlCreateEdit("", 8, 16, 265, 337) GUICtrlSetData(-1, "Press a button!"&@CRLF) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 If $LAST = 1 Then Soundplay ( "./Beep1.wav" ) GUICtrlSetData($Whattodo, Random(1,3,1)&@crlf, 1); ----------------------This random needs to be equal to $LAST = Random(1,3,1);-------------------------------------------------- this random else GUICtrlSetData($Whattodo, "WRONG"&@crlf, 1) $LAST = Random(1,3,1) EndIf Case $Button2 If $LAST = 2 Then Soundplay ( "./Beep2.wav" ) GUICtrlSetData($Whattodo, Random(1,3,1)&@crlf, 1) $LAST = Random(1,3,1) else GUICtrlSetData($Whattodo, "WRONG"&@crlf, 1) $LAST = Random(1,3,1) EndIf Case $Button3 If $LAST = 3 Then Soundplay ( "./Beep3.wav" ) GUICtrlSetData($Whattodo, Random(1,3,1)&@crlf, 1) $LAST = Random(1,3,1) else GUICtrlSetData($Whattodo, "WRONG"&@crlf, 1) $LAST = Random(1,3,1) EndIf EndSwitch WEnd Edited October 3, 2008 by nf67 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