Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Setting up a timer


  • Please log in to reply
11 replies to this topic

#1 nf67

nf67

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 316 posts

Posted 04 October 2008 - 03:34 PM

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

P.S: Sorry for PMing you Zedna

Edited by nf67, 04 October 2008 - 03:34 PM.








#2 ProgAndy

ProgAndy

    You need AutoItObject

  • MVPs
  • 2,508 posts

Posted 04 October 2008 - 03:53 PM

Look at TimerInit and TimerDiff. THe Difference is then returned in milliseconds.
*GERMAN* Posted Image [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

#3 Valuater

Valuater

    www.PayFreeWireless.com

  • MVPs
  • 11,196 posts

Posted 04 October 2008 - 03:54 PM

From Autoit Wrappers...

AutoIt         
;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=133769


8)

Posted Image

Clic The Pic!!!


#4 martin

martin

    ~~\o/~~~/0\=¬''~~~

  • MVPs
  • 7,313 posts

Posted 04 October 2008 - 03:56 PM

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

P.S: Sorry for PMing you Zedna

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 <Timers.au3> _Timer_SetTimer($myGui,180000,"TimeUp") . . Func TimeUp($a,$b,$c,$d)   MsgBox ( 0, "Game Over", "Out of time" ,5)   exit EndFunc

  • header127 likes this
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.

#5 Zedna

Zedna

    AutoIt rulez!

  • MVPs
  • 8,557 posts

Posted 04 October 2008 - 04:06 PM

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 by Zedna, 04 October 2008 - 04:06 PM.


#6 nf67

nf67

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 316 posts

Posted 04 October 2008 - 04:19 PM

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:

Plain Text         
#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 by nf67, 04 October 2008 - 04:21 PM.


#7 trancexx

trancexx

    Queen F. Elizabeth MCXI

  • Active Members
  • PipPipPipPipPipPip
  • 5,991 posts

Posted 04 October 2008 - 04:19 PM

I'm sure Zedna meant ">" instead of "="

Maybe I'm in love (Sshh, it's a secret)

.

 

eMyvnE


#8 Zedna

Zedna

    AutoIt rulez!

  • MVPs
  • 8,557 posts

Posted 04 October 2008 - 04:25 PM

I'm sure Zedna meant ">" instead of "="


Of course you are right.

#9 ProgAndy

ProgAndy

    You need AutoItObject

  • MVPs
  • 2,508 posts

Posted 04 October 2008 - 04:26 PM

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* Posted Image [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

#10 Hawk

Hawk

    Seeker

  • Active Members
  • 32 posts

Posted 06 March 2012 - 04:41 PM

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 by Hawk, 06 March 2012 - 04:41 PM.


#11 JohnQSmith

JohnQSmith

    Universalist

  • Active Members
  • PipPipPipPipPip
  • 262 posts

Posted 06 March 2012 - 06:07 PM

Sorry for digging this topic

Instead 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".


#12 Hawk

Hawk

    Seeker

  • Active Members
  • 32 posts

Posted 11 March 2012 - 04:30 PM

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 :oops:




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users