nf67 Posted October 4, 2008 Share Posted October 4, 2008 (edited) Is it possible to set up a timer like this? Start Timer If Timer hits 3 mins. Then MsgBox ( 0, "Game Over", "Out of time" ) Endif If so, how can I do this? Thanks P.S: Sorry for PMing you Zedna Edited October 4, 2008 by nf67 Link to comment Share on other sites More sharing options...
ProgAndy Posted October 4, 2008 Share Posted October 4, 2008 Look at TimerInit and TimerDiff. THe Difference is then returned in milliseconds. *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
Valuater Posted October 4, 2008 Share Posted October 4, 2008 From Autoit Wrappers...;Time Machine #1 ;Minutes/seconds/miliseconds ; Author - Valuater $Minutes = 90 ; will wait 90 minutes Local $60Count = 0, $begin = TimerInit() While $Minutes > $60Count $dif = TimerDiff($begin) $dif2 = StringLeft($dif, StringInStr($dif, ".") -1) $Count = int($dif/1000) $60Count = Int($Count / 60) ToolTip("Minutes Required = " & $Minutes & @CRLF & "Minutes Past = " & $60Count & @CRLF & "Seconds Count = " & $Count & @CRLF & "Mili-Seconds Count = " & $dif2, 20, 20, "Time Machine #1", 1) Sleep(20) WEnd MsgBox(64, "Time-Up!!", "Your " & $Minutes & " minutes have passed ")There are many more examples here...http://www.autoitscript.com/forum/index.ph...st&p=1337698) Link to comment Share on other sites More sharing options...
martin Posted October 4, 2008 Share Posted October 4, 2008 Is it possible to set up a timer like this? Start Timer If Timer hits 3 mins. Then MsgBox ( 0, "Game Over", "Out of time" ) Endif If so, how can I do this? Thanks P.S: Sorry for PMing you ZednaLook up _Timer_SetTimer. Note that the function called by the timer must have 4 parameters or it won't work. The help doesn't tell you this. You don't have to use the parameters. #include <Timers.au3> _Timer_SetTimer($myGui,180000,"TimeUp") . . Func TimeUp($a,$b,$c,$d) MsgBox ( 0, "Game Over", "Out of time" ,5) exit EndFunc Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Zedna Posted October 4, 2008 Share Posted October 4, 2008 (edited) Sleep(3000) MsgBox ( 0, "Game Over", "Out of time" ) $start = TimerInit() While 1 If TimerDiff($start) = 3000 Then ExitLoop Sleep(10) WEnd MsgBox ( 0, "Game Over", "Out of time" ) Edited October 4, 2008 by Zedna Resources UDF Â ResourcesEx UDF Â AutoIt Forum Search Link to comment Share on other sites More sharing options...
nf67 Posted October 4, 2008 Author Share Posted October 4, 2008 (edited) I think I get it, but I don't know where to put it... If TimerDiff($start) = 3000 Then MsgBox ( 0, "Game Over", "Out of time") EndIf if 1 then;if you press Ok then $Points = $Points-$Points ;Reset points to 0 GUICtrlSetData($Score, $Points); Set score to points (0) Endif This is my code: expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GUIConstants.au3> #include <WindowsConstants.au3> Global $LAST = 1 Global $Points = 0 $start = TimerInit() MsgBox ( 0, "Game Over", "Out of time" ) $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) ;Key bindings? $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 If $LAST = 1 Then $Points = $Points+25 GUICtrlSetData ($Score, $Points) Beep ( 600, 500) $LAST = Random(1,4,1) GUICtrlSetData($Commander, $LAST&@crlf, 1) else $Points = $Points-50 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 GUICtrlSetData ($Score, $Points) Beep ( 500, 500) $LAST = Random(1,4,1) GUICtrlSetData($Commander, $LAST&@crlf, 1) else $Points = $Points-50 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 GUICtrlSetData ($Score, $Points) Beep ( 400, 500) $LAST = Random(1,4,1) GUICtrlSetData($Commander, $LAST&@crlf, 1) else $Points = $Points-50 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 GUICtrlSetData ($Score, $Points) Beep (300, 500) $LAST = Random(1,4,1) GUICtrlSetData($Commander, $LAST&@crlf, 1) else $Points = $Points-50 GUICtrlSetData ($Score, $Points) GUICtrlSetData($Commander, "(-.-)"&@crlf, 1) Beep ( 100, 1500 ) $LAST = Random(1,4,1) GUICtrlSetData($Commander, $LAST&@crlf, 1) EndIf EndSwitch WEnd Edited October 4, 2008 by nf67 Link to comment Share on other sites More sharing options...
trancexx Posted October 4, 2008 Share Posted October 4, 2008 I'm sure Zedna meant ">" instead of "=" ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Zedna Posted October 4, 2008 Share Posted October 4, 2008 I'm sure Zedna meant ">" instead of "="Of course you are right. Resources UDF Â ResourcesEx UDF Â AutoIt Forum Search Link to comment Share on other sites More sharing options...
ProgAndy Posted October 4, 2008 Share Posted October 4, 2008 Add it at this position: Init it before the loop and check in the loop. GUISetState(@SW_SHOW) Global $TIMER = TimerInit() Global Const $TIMEOUT = 10000; 10 seconds While 1 If TimerDiff($TIMER) >= $TIMEOUT Then MsgBox(0,"","Out of time") ExitLoop EndIf $nMsg = GUIGetMsg() *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
Hawk Posted March 6, 2012 Share Posted March 6, 2012 (edited) Look up _Timer_SetTimer. Note that the function called by the timer must have 4 parameters or it won't work. The help doesn't tell you this. You don't have to use the parameters. #include _Timer_SetTimer($myGui,180000,"TimeUp") . . Func TimeUp($a,$b,$c,$d) MsgBox ( 0, "Game Over", "Out of time" ,5) exit EndFunc Sorry for digging this topic, but I was searching half an hour now to find an error in my code that uses _Timer_SetTimer(). The application randomly stopped responding (">Process failed to respond; forcing abrupt termination...") and/or allocated gigabytes of memory crashing some of my applications running at that time. Only now I remembered your post that having 4 paramters in the function to be called is so important. When I created another such function, I forgot about it, that was the mistake. It's really important to have 4 arguments in the function you want to be called! I just want to point to the neccessity of this. Edited March 6, 2012 by Hawk Link to comment Share on other sites More sharing options...
JohnQSmith Posted March 6, 2012 Share Posted March 6, 2012 Sorry for digging this topicInstead of necroing an ancient topic, create a new one and add a link to the one you're referencing. Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes". Link to comment Share on other sites More sharing options...
Hawk Posted March 11, 2012 Share Posted March 11, 2012 Instead of necroing an ancient topic, create a new one and add a link to the one you're referencing.What for? I didn't have a problem that doesn't fit to this thread. I wanted a way to use timers, found this topic through forum search and programmed based on the posts here. So if anybody else wants to program timers, finds this thread with some nice examples and then saves himself half an hour of frustration because he has also read my post, then I am happy 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