nf67 Posted October 5, 2008 Share Posted October 5, 2008 (edited) Hi there , If I have some commands under $Case Button1 can I just paste these commands between Func ButtonPress() ;and EndFunc , and then bind the function to a hotkey with HotKeySet ("1", ButtonPress1())? Or do I need to adjust them because the commands triggered by a button and a function don't get scripted the same way? P.S: Will put some code up soon, it's on a different PC. Edited October 5, 2008 by nf67 Link to comment Share on other sites More sharing options...
Valuater Posted October 5, 2008 Share Posted October 5, 2008 Your code will make it a lot easier to figure out what you want 8) Link to comment Share on other sites More sharing options...
nf67 Posted October 5, 2008 Author Share Posted October 5, 2008 (edited) expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GUIConstants.au3> #include <WindowsConstants.au3> #Include <Timers.au3> Global $LAST = 1 Global $Points = 0 Global $Streak = 0 Global $TIMER = TimerInit() Global Const $TIMEOUT = 60000 $Slothor = GUICreate("Slothor", 173, 213, 192, 114) $Commander = GUICtrlCreateEdit("1", 5, 10, 160, 120, BitOR($ES_CENTER,$ES_AUTOVSCROLL,$ES_WANTRETURN,$ES_READONLY,$ES_AUTOHSCROLL)) GUICtrlSetFont(-1, 37, 800, 0, "Arial") $Button1 = GUICtrlCreateButton("1", 5, 128, 40, 60) $Button2 = GUICtrlCreateButton("2", 45, 128, 40, 60) $Button3 = GUICtrlCreateButton("3", 85, 128, 40, 60) $Button4 = GUICtrlCreateButton("4", 125, 128, 40, 60) $Score = GUICtrlCreateEdit("", 5, 184, 161, 25, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_WANTRETURN,$ES_READONLY)) GUICtrlSetData(-1, "Score") GUICtrlSetFont(-1, 12, 800, 2, "Arial") GUISetState(@SW_SHOW) ;--------------------------------------------------We're talking about this part of the code HotKeySet ("1", Press1()) Func Press1() If $LAST = 1 Then $Points = $Points+25 $Streak = $Streak+1 GUICtrlSetData ($Score, $Points) Beep ( 600, 250) $LAST = Random(1,4,1) GUICtrlSetData($Commander, $LAST&@crlf, 1) else $Points = $Points-50 $Streak = $Streak-$Streak GUICtrlSetData ($Score, $Points) GUICtrlSetData($Commander, "(-.-)"&@crlf, 1) Beep ( 100, 1500 ) $LAST = Random(1,4,1) GUICtrlSetData($Commander, $LAST&@crlf, 1) EndIf EndFunc ;--------------------------------------------------------------------------------------- While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 If $LAST = 1 Then $Points = $Points+25 $Streak = $Streak+1 GUICtrlSetData ($Score, $Points) Beep ( 600, 250) $LAST = Random(1,4,1) GUICtrlSetData($Commander, $LAST&@crlf, 1) else $Points = $Points-50 $Streak = $Streak-$Streak GUICtrlSetData ($Score, $Points) GUICtrlSetData($Commander, "(-.-)"&@crlf, 1) Beep ( 100, 1500 ) $LAST = Random(1,4,1) GUICtrlSetData($Commander, $LAST&@crlf, 1) EndIf Case $Button2 If $LAST = 2 Then $Points = $Points+25 $Streak = $Streak+1 GUICtrlSetData ($Score, $Points) Beep ( 500, 250) $LAST = Random(1,4,1) GUICtrlSetData($Commander, $LAST&@crlf, 1) else $Points = $Points-50 $Streak = $Streak-$Streak GUICtrlSetData ($Score, $Points) GUICtrlSetData($Commander, "(-.-)"&@crlf, 1) Beep ( 100, 1500 ) $LAST = Random(1,4,1) GUICtrlSetData($Commander, $LAST&@crlf, 1) EndIf Case $Button3 If $LAST = 3 Then $Points = $Points+25 $Streak = $Streak+1 GUICtrlSetData ($Score, $Points) Beep ( 400, 250) $LAST = Random(1,4,1) GUICtrlSetData($Commander, $LAST&@crlf, 1) else $Points = $Points-50 $Streak = $Streak-$Streak GUICtrlSetData ($Score, $Points) GUICtrlSetData($Commander, "(-.-)"&@crlf, 1) Beep ( 100, 1500 ) $LAST = Random(1,4,1) GUICtrlSetData($Commander, $LAST&@crlf, 1) EndIf Case $Button4 If $LAST = 4 Then $Points = $Points+25 $Streak = $Streak+1 GUICtrlSetData ($Score, $Points) Beep (300, 250) $LAST = Random(1,4,1) GUICtrlSetData($Commander, $LAST&@crlf, 1) else $Points = $Points-50 $Streak = $Streak-$Streak GUICtrlSetData ($Score, $Points) GUICtrlSetData($Commander, "(-.-)"&@crlf, 1) Beep ( 100, 1500 ) $LAST = Random(1,4,1) GUICtrlSetData($Commander, $LAST&@crlf, 1) EndIf EndSwitch If $Streak=15 Then $Points=$Points+200 GUICtrlSetData ($Score, $Points) GUICtrlSetData($Commander, "+200"&@crlf, 1) Beep (900, 1500) $Streak = $Streak+1 $LAST = Random(1,4,1) Sleep (300) GUICtrlSetData($Commander, $LAST&@crlf, 1) EndIf If TimerDiff($TIMER) > $TIMEOUT Then $RetryAnswer = MsgBox(36, "Game Over", "You scored "&$Points &" points. Retry?", 5000) Select Case $RetryAnswer = 6 WinKill ( "Game Over" ) FileWrite(@ScriptDir & "\Scores.txt", $Points&@CRLF) $Streak = 0 $Points = 0 GuiCtrlSetData ($Score, $Points) _Timer_KillTimer($Slothor, $TIMER) Global $TIMER = TimerInit() Case $RetryAnswer = 7 WinKill ( "Game Over" ) GUISetState(@SW_HIDE, $Slothor) FileWrite(@ScriptDir & "\Scores.txt", $Points&@CRLF) $Scores = FileRead(@ScriptDir & "\Scores.txt") $Highscores = GUICreate("Highscores", 163, 58, 193, 115) $ScoreView = GUICtrlCreateEdit("Scores:"&@CRLF & $Scores, 0, 0, 161, 57, BitOR($ES_WANTRETURN,$WS_VSCROLL,$ES_READONLY)) GUISetState(@SW_SHOW) While 3 $msg3 = GUIGetMsg() Select Case $msg3 = $GUI_EVENT_CLOSE WinKill ("Slothor") ExitLoop EndSelect WEnd EndSelect EndIf WEnd As you can see, I want to let the Hotkey do the same thing as Button1 by using a function. Edited October 5, 2008 by nf67 Link to comment Share on other sites More sharing options...
ResNullius Posted October 5, 2008 Share Posted October 5, 2008 (edited) Replace your statements under your Case command with the function call:While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 Press1()Edit: By the way, your syntax for HotkeySet is wrong:, you don't use the brackets after the function name, and you need to put the function name in quotes:should beHotKeySet ("1", "Press1") Edited October 5, 2008 by ResNullius Link to comment Share on other sites More sharing options...
nf67 Posted October 5, 2008 Author Share Posted October 5, 2008 (edited) Thanks Res, it works, although I did not understand what you ment with the first piece of code, but that's probably not your fault. Edited October 5, 2008 by nf67 Link to comment Share on other sites More sharing options...
Valuater Posted October 5, 2008 Share Posted October 5, 2008 Please, you don't need to send me two PM's expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Timers.au3> Global $LAST = 1 Global $Points = 0 Global $Streak = 0 Global $TIMER = TimerInit() Global Const $TIMEOUT = 60000 HotKeySet("1", "Press1") $Slothor = GUICreate("Slothor", 173, 213, 192, 114) $Commander = GUICtrlCreateEdit("1", 5, 10, 160, 120, BitOR($ES_CENTER, $ES_AUTOVSCROLL, $ES_WANTRETURN, $ES_READONLY, $ES_AUTOHSCROLL)) GUICtrlSetFont(-1, 37, 800, 0, "Arial") $Button1 = GUICtrlCreateButton("1", 5, 128, 40, 60) $Button2 = GUICtrlCreateButton("2", 45, 128, 40, 60) $Button3 = GUICtrlCreateButton("3", 85, 128, 40, 60) $Button4 = GUICtrlCreateButton("4", 125, 128, 40, 60) $Score = GUICtrlCreateEdit("", 5, 184, 161, 25, BitOR($ES_CENTER, $ES_AUTOHSCROLL, $ES_WANTRETURN, $ES_READONLY)) GUICtrlSetData(-1, "Score") GUICtrlSetFont(-1, 12, 800, 2, "Arial") GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 Press1() Case $Button2 If $LAST = 2 Then $Points = $Points + 25 $Streak = $Streak + 1 GUICtrlSetData($Score, $Points) Beep(500, 250) $LAST = Random(1, 4, 1) GUICtrlSetData($Commander, $LAST & @CRLF, 1) Else $Points = $Points - 50 $Streak = $Streak - $Streak GUICtrlSetData($Score, $Points) GUICtrlSetData($Commander, "(-.-)" & @CRLF, 1) Beep(100, 1500) $LAST = Random(1, 4, 1) GUICtrlSetData($Commander, $LAST & @CRLF, 1) EndIf Case $Button3 If $LAST = 3 Then $Points = $Points + 25 $Streak = $Streak + 1 GUICtrlSetData($Score, $Points) Beep(400, 250) $LAST = Random(1, 4, 1) GUICtrlSetData($Commander, $LAST & @CRLF, 1) Else $Points = $Points - 50 $Streak = $Streak - $Streak GUICtrlSetData($Score, $Points) GUICtrlSetData($Commander, "(-.-)" & @CRLF, 1) Beep(100, 1500) $LAST = Random(1, 4, 1) GUICtrlSetData($Commander, $LAST & @CRLF, 1) EndIf Case $Button4 If $LAST = 4 Then $Points = $Points + 25 $Streak = $Streak + 1 GUICtrlSetData($Score, $Points) Beep(300, 250) $LAST = Random(1, 4, 1) GUICtrlSetData($Commander, $LAST & @CRLF, 1) Else $Points = $Points - 50 $Streak = $Streak - $Streak GUICtrlSetData($Score, $Points) GUICtrlSetData($Commander, "(-.-)" & @CRLF, 1) Beep(100, 1500) $LAST = Random(1, 4, 1) GUICtrlSetData($Commander, $LAST & @CRLF, 1) EndIf EndSwitch If $Streak = 15 Then $Points = $Points + 200 GUICtrlSetData($Score, $Points) GUICtrlSetData($Commander, "+200" & @CRLF, 1) Beep(900, 1500) $Streak = $Streak + 1 $LAST = Random(1, 4, 1) Sleep(300) GUICtrlSetData($Commander, $LAST & @CRLF, 1) EndIf If TimerDiff($TIMER) > $TIMEOUT Then $RetryAnswer = MsgBox(36, "Game Over", "You scored " & $Points & " points. Retry?", 5000) Select Case $RetryAnswer = 6 WinKill("Game Over") FileWrite(@ScriptDir & "\Scores.txt", $Points & @CRLF) $Streak = 0 $Points = 0 GUICtrlSetData($Score, $Points) _Timer_KillTimer($Slothor, $TIMER) Global $TIMER = TimerInit() Case $RetryAnswer = 7 WinKill("Game Over") GUISetState(@SW_HIDE, $Slothor) FileWrite(@ScriptDir & "\Scores.txt", $Points & @CRLF) $Scores = FileRead(@ScriptDir & "\Scores.txt") $Highscores = GUICreate("Highscores", 163, 58, 193, 115) $ScoreView = GUICtrlCreateEdit("Scores:" & @CRLF & $Scores, 0, 0, 161, 57, BitOR($ES_WANTRETURN, $WS_VSCROLL, $ES_READONLY)) GUISetState(@SW_SHOW) While 3 $msg3 = GUIGetMsg() Select Case $msg3 = $GUI_EVENT_CLOSE WinKill("Slothor") ExitLoop EndSelect WEnd EndSelect EndIf WEnd ; ------------------ Functions ------------------------------- Func Press1() If $LAST = 1 Then $Points = $Points + 25 $Streak = $Streak + 1 GUICtrlSetData($Score, $Points) Beep(600, 250) $LAST = Random(1, 4, 1) GUICtrlSetData($Commander, $LAST & @CRLF, 1) Else $Points = $Points - 50 $Streak = $Streak - $Streak GUICtrlSetData($Score, $Points) GUICtrlSetData($Commander, "(-.-)" & @CRLF, 1) Beep(100, 1500) $LAST = Random(1, 4, 1) GUICtrlSetData($Commander, $LAST & @CRLF, 1) EndIf EndFunc ;==>Press1 8) Link to comment Share on other sites More sharing options...
nf67 Posted October 5, 2008 Author Share Posted October 5, 2008 I know I don't have to, but I thought the first one might not have reached you. ( As I said in the PM itself ) Thanks for your help mate 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