nf67 Posted October 12, 2008 Share Posted October 12, 2008 (edited) Hi there, I have a timer in my script, it starts after 5 is pressed, and ends with a MsgBox at 60 seconds. Now I was wondering, is it possible to make a Progressbar that indicates the time used/left? I have totally no idea how to do this, but I did create a Progressbar already . The progressbar should start running when 5 is pressed ( same as the timer ) and be filled in 60 seconds ( at the time the timer stops ). Any help is appreaciated, here's my code: expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GUIConstants.au3> #include <WindowsConstants.au3> #include <Constants.au3> #Include <Timers.au3> #include <ProgressConstants.au3> Global $TIMER = TimerInit() Global $LAST = Random(1,4,1) Global $Points = 0 Global $Streak = 0 Global $Sound = 1 Global Const $TIMEOUT = 60000 $Slothor = GUICreate("Slothor", 173, 235, 192, 114) GUISetBkColor(0x343434, $Slothor) $Commander = GUICtrlCreateEdit("GO 5"&@crlf, 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) GUICtrlSetBkColor(-1, 0x204383) GUICtrlSetState ($Button1, $GUI_DISABLE) $Button2 = GUICtrlCreateButton("2", 45, 128, 40, 60) GUICtrlSetBkColor(-1, 0x918A39) GUICtrlSetState ($Button2, $GUI_DISABLE) $Button3 = GUICtrlCreateButton("3", 85, 128, 40, 60) GUICtrlSetBkColor(-1, 0x7B1314) GUICtrlSetState ($Button3, $GUI_DISABLE) $Button4 = GUICtrlCreateButton("4", 125, 128, 40, 60) GUICtrlSetBkColor(-1, 0x196C38) GUICtrlSetState ($Button4, $GUI_DISABLE) $Score = GUICtrlCreateEdit("Score", 5, 184, 140, 25, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_WANTRETURN,$ES_READONLY)) GUICtrlSetFont(-1, 12, 800, 2, "Arial") $Combocount = GUICtrlCreateEdit("C", 145, 184, 20, 25, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_WANTRETURN,$ES_READONLY)) GUICtrlSetFont(-1, 12, 800, 2, "Arial") $Timetrack = GUICtrlCreateProgress(5, 208, 140, 20, $PBS_SMOOTH); <--------------------------------ProgressBar $S = GUICtrlCreateButton("S", 145, 208, 20, 20) GUISetState(@SW_SHOW) ControlFocus ( "Slothor", "", $Button1) HotKeySet ("5", "Go") Func Go() GUICtrlSetState ($Button1, $GUI_ENABLE) GUICtrlSetState ($Button2, $GUI_ENABLE) GUICtrlSetState ($Button3, $GUI_ENABLE) GUICtrlSetState ($Button4, $GUI_ENABLE) _Timer_KillTimer($Slothor, $TIMER) $TIMER = TimerInit() $LAST = Random(1,4,1) $Points = 0 $Streak = 0 GUICtrlSetData ($Score, $Points) GUICtrlSetData($Commander, $LAST&@crlf, 1) ;Set ProgressBar to 0 (Set to 0 first, because 5 can be pressed again when the game is over and the bar is full already!) ;Start ProgressBar! EndFunc HotKeySet ("1", "Press1") Func Press1() If $LAST = 1 Then $Streak = $Streak+1 if $Streak > 0 then $Points = $Points+25 endif if $Streak > 15 then $Points = $Points+25 endif if $Streak > 35 then $Points = $Points+25 endif if $Streak > 55 then $Points = $Points+25 endif if $Streak > 70 then $Points = $Points+25 endif if $Streak > 95 then $Points = $Points+25 endif GUICtrlSetData ($Score, $Points) If $Sound = 1 Then Beep (600, 50) Else Sleep (50) Endif $LAST = Random(1,4,1) GUICtrlSetData($Commander, $LAST&@crlf, 1) else $Points = $Points-50 $Streak = $Streak-$Streak GUICtrlSetData ($Score, $Points) GUICtrlSetData($Commander, "(-.-)"&@crlf, 1) if $Sound = 1 Then Beep ( 100, 1500 ) else Sleep (1500) Endif $LAST = Random(1,4,1) GUICtrlSetData($Commander, $LAST&@crlf, 1) EndIf EndFunc HotKeySet ("2", "Press2") Func Press2() If $LAST = 2 Then $Streak = $Streak+1 if $Streak > 0 then $Points = $Points+25 endif if $Streak > 15 then $Points = $Points+25 endif if $Streak > 35 then $Points = $Points+25 endif if $Streak > 55 then $Points = $Points+25 endif if $Streak > 70 then $Points = $Points+25 endif if $Streak > 95 then $Points = $Points+25 endif if $Streak > 0 then $Points = $Points+25 endif GUICtrlSetData ($Score, $Points) If $Sound = 1 Then Beep (500, 50) Else Sleep (50) Endif $LAST = Random(1,4,1) GUICtrlSetData($Commander, $LAST&@crlf, 1) else $Points = $Points-50 $Streak = $Streak-$Streak GUICtrlSetData ($Score, $Points) GUICtrlSetData($Commander, "(-.-)"&@crlf, 1) if $Sound = 1 Then Beep ( 100, 1500 ) else Sleep (1500) Endif $LAST = Random(1,4,1) GUICtrlSetData($Commander, $LAST&@crlf, 1) EndIf EndFunc HotKeySet ("3", "Press3") Func Press3() If $LAST = 3 Then $Streak = $Streak+1 if $Streak > 0 then $Points = $Points+25 endif if $Streak > 15 then $Points = $Points+25 endif if $Streak > 35 then $Points = $Points+25 endif if $Streak > 55 then $Points = $Points+25 endif if $Streak > 70 then $Points = $Points+25 endif if $Streak > 95 then $Points = $Points+25 endif GUICtrlSetData ($Score, $Points) If $Sound = 1 Then Beep (400, 50) Else Sleep (50) Endif $LAST = Random(1,4,1) GUICtrlSetData($Commander, $LAST&@crlf, 1) else $Points = $Points-50 $Streak = $Streak-$Streak GUICtrlSetData ($Score, $Points) GUICtrlSetData($Commander, "(-.-)"&@crlf, 1) if $Sound = 1 Then Beep ( 100, 1500 ) else Sleep (1500) Endif $LAST = Random(1,4,1) GUICtrlSetData($Commander, $LAST&@crlf, 1) EndIf EndFunc HotKeySet ("4", "Press4") Func Press4() If $LAST = 4 Then $Streak = $Streak+1 if $Streak > 0 then $Points = $Points+25 endif if $Streak > 15 then $Points = $Points+25 endif if $Streak > 35 then $Points = $Points+25 endif if $Streak > 55 then $Points = $Points+25 endif if $Streak > 70 then $Points = $Points+25 endif if $Streak > 95 then $Points = $Points+25 endif GUICtrlSetData ($Score, $Points) If $Sound = 1 Then Beep (300, 50) Else Sleep (50) Endif $LAST = Random(1,4,1) GUICtrlSetData($Commander, $LAST&@crlf, 1) else $Points = $Points-50 $Streak = $Streak-$Streak GUICtrlSetData ($Score, $Points) GUICtrlSetData($Commander, "(-.-)"&@crlf, 1) if $Sound = 1 Then Beep ( 100, 1500 ) else Sleep (1500) Endif $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 Press1() Case $Button2 Press2() Case $Button3 Press3() Case $Button4 Press4() Case $S if $Sound = 0 Then $Sound = 1 else $Sound = 0 Endif EndSwitch If $Streak = 0 Then GUICtrlSetData ($Combocount, "1") EndIf If $Streak = 15 Then GUICtrlSetData ($Combocount, "2") EndIf If $Streak = 35 Then GUICtrlSetData ($Combocount, "3") EndIf If $Streak = 55 Then GUICtrlSetData ($Combocount, "4") EndIf If $Streak = 70 Then GUICtrlSetData ($Combocount, "5") EndIf If TimerDiff($TIMER) > $TIMEOUT Then FileWrite(@ScriptDir & "\Scores.txt", $Points&@CRLF) $Last = 0 $RetryAnswer = MsgBox(36, "Game Over", "You scored "&$Points &" points. Retry?", 5000) Select Case $RetryAnswer = 6 GUICtrlSetState ($Button1, $GUI_DISABLE) GUICtrlSetState ($Button2, $GUI_DISABLE) GUICtrlSetState ($Button3, $GUI_DISABLE) GUICtrlSetState ($Button4, $GUI_DISABLE) _Timer_KillTimer($Slothor, $TIMER) $TIMER = TimerInit() GUICtrlSetData($Commander, "GO 5"&@crlf, 1) Case $RetryAnswer = 7 WinKill ( "Game Over" ) GUISetState(@SW_HIDE, $Slothor) $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 Thanks Edited October 12, 2008 by nf67 Link to comment Share on other sites More sharing options...
monoceres Posted October 12, 2008 Share Posted October 12, 2008 Sample how one could do it: #include <StaticConstants.au3> Global $time=60 Opt("GUIOnEventMode",1) $hwnd=GUICreate("Time left",300,60) $progress=GUICtrlCreateProgress(10,25,280,25) GUICtrlSetData(-1,100) Sleep(500); Fill up progress $label=GUICtrlCreateLabel("Time Until Termination: "&$time&" seconds.",10,5,280,15,$SS_CENTER) GUISetOnEvent(-3,"close") GUISetState() $timer=TimerInit() Do Sleep(1000) GUICtrlSetData($label,"Time Until Termination: "&Round($time-TimerDiff($timer)/1000)&" seconds.") $timespend=TimerDiff($timer)/1000 GUICtrlSetData($progress,100-($timespend/$time*100)) If $timespend>=$time Then close() Until False Func close() Exit EndFunc Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
Marlo Posted October 12, 2008 Share Posted October 12, 2008 I'm sorry but Monoceres has the best avatar ever (Charlie in a nazi's hat ) Sunny ftw Click here for the best AutoIt help possible.Currently Working on: Autoit RAT Link to comment Share on other sites More sharing options...
nf67 Posted October 17, 2008 Author Share Posted October 17, 2008 Sample how one could do it: #include <StaticConstants.au3> Global $time=60 Opt("GUIOnEventMode",1) $hwnd=GUICreate("Time left",300,60) $progress=GUICtrlCreateProgress(10,25,280,25) GUICtrlSetData(-1,100) Sleep(500); Fill up progress $label=GUICtrlCreateLabel("Time Until Termination: "&$time&" seconds.",10,5,280,15,$SS_CENTER) GUISetOnEvent(-3,"close") GUISetState() $timer=TimerInit() Do Sleep(1000) GUICtrlSetData($label,"Time Until Termination: "&Round($time-TimerDiff($timer)/1000)&" seconds.") $timespend=TimerDiff($timer)/1000 GUICtrlSetData($progress,100-($timespend/$time*100)) If $timespend>=$time Then close() Until False Func close() Exit EndFunc Thanks, I tried to implent it but it seems that it blocks some other things for some reason . This is what I did: HotKeySet ("5", "Go") Func Go() GUICtrlSetState ($Button1, $GUI_ENABLE) GUICtrlSetState ($Button2, $GUI_ENABLE) GUICtrlSetState ($Button3, $GUI_ENABLE) GUICtrlSetState ($Button4, $GUI_ENABLE) _Timer_KillTimer($Slothor, $TIMER) $TIMER = TimerInit() $LAST = Random(1,4,1) $Points = 0 $Streak = 0 GUICtrlSetData ($Score, $Points) GUICtrlSetData($Commander, $LAST&@crlf, 1) GUICtrlSetData($Timetrack,100);Set ProgressBar to full TimeLeft();Start ProgressBar (See below)! EndFunc Func Timeleft() $TimeValue = 100;Set the timevalue Do;Repeat until time's up Sleep (1000);After every second $TimeValue = $TimeValue - (100/60); Timevalue is decreased by 100/60 GuiCtrlSetData($Timetrack, $TimeValue);And the progressbar is set to the timevalue Until $TimeValue = 0 ; Until there is no more time left EndFunc The ProgressBar is running fine now, but the Combocounter ($ComboCount, it updates when $Streak is at a certain value, $Streak increases every time you press the right button) doesn't work anymore (it never updates) , neither does the "real" timer ($TIMER) (It doesn't MsgBox when you're out of time anymore). Maybe this is because the script is "stuck" in the Do... Until loop? But then it'd be strange that it still does the other things, like beeping. Please help, Link to comment Share on other sites More sharing options...
kjcdude Posted October 24, 2008 Share Posted October 24, 2008 here's one i'm working on not sure how well it applies to what you need. 2 issues i'm running into though. 1. How to keep the seconds ($difms) complient with time standards. Currently it's just a ticking clock, it should restart at 59 2. How to keep the minutes and hours accurate. Currently they round everything which causes inaccurate hours and minutes. $begin = TimerInit() $h1 = @DesktopHeight $w1 = @DesktopWidth ProgressOn("Timer", "Starting", "0%", $w1-300, "0") $totaltimep = 5000;in seconds While 1 $difm = TimerDiff($begin)/1000 $prcts = Round(($difm/$totaltimep) * 100, 2) if $difm >= $totaltimep Then MsgBox(0, "", "overtime") ExitLoop EndIf $difms = Round($difm, 0) $difmm = Round(($difm/60), 0) $difmh = Round(($difm/60)/60, 0) ProgressSet($prcts, $prcts & "%", "Total Time - " & $difmh & ":" & $difmm & ":" & $difms) sleep(500) WEnd Link to comment Share on other sites More sharing options...
kjcdude Posted October 24, 2008 Share Posted October 24, 2008 (edited) Correctly working version. #include <Date.au3> $begin = TimerInit() $h1 = @DesktopHeight $w1 = @DesktopWidth Global $Secs1, $Mins1, $Hour1 ProgressOn("Timer", "Starting", "0%", $w1-300, "0") $totaltimep = 300;in seconds While 1 $timerm = TimerDiff($begin) $difm = $timerm/1000 if $difm >= $totaltimep Then MsgBox(0, "", "Finished") ProgressOff() ExitLoop EndIf _TicksToTime($timerm, $Hour1, $Mins1, $Secs1) $prcts = Round(($difm/$totaltimep) * 100, 2) _TicksToTime($timerm, $Hour1, $Mins1, $Secs1) $Timef = StringFormat("%02i:%02i:%02i", $Hour1, $Mins1, $Secs1) ProgressSet($prcts, $prcts & "%", "Total Time - " & $Timef) sleep(500) WEnd Edited October 24, 2008 by kjcdude 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