Sign in to follow this  
Followers 0

Setting up a timer

12 posts in this topic

Posted (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

P.S: Sorry for PMing you Zedna

Edited by nf67

Share this post


Link to post
Share on other sites



Posted

Look at TimerInit and TimerDiff. THe Difference is then returned in milliseconds.

Share this post


Link to post
Share on other sites

Posted

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

8)

Share this post


Link to post
Share on other sites

Posted

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

Share this post


Link to post
Share on other sites

Posted (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 by Zedna

Share this post


Link to post
Share on other sites

Posted (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:

#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

Share this post


Link to post
Share on other sites

Posted

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

Share this post


Link to post
Share on other sites

Posted

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

Of course you are right.

Share this post


Link to post
Share on other sites

Posted

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()

Share this post


Link to post
Share on other sites

Posted (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 by Hawk

Share this post


Link to post
Share on other sites

Posted

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.

Share this post


Link to post
Share on other sites

Posted

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:

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0