Sign in to follow this  
Followers 0

Setting up a timer

12 posts in this topic

#1 ·  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



#2 ·  Posted

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

Share this post


Link to post
Share on other sites

#3 ·  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)


Ad_Smallest_zpsjjqeqtel.jpg

Share this post


Link to post
Share on other sites

#4 ·  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
1 person 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.

Share this post


Link to post
Share on other sites

#5 ·  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

#6 ·  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

#7 ·  Posted

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


 

.

eMyvnE

Share this post


Link to post
Share on other sites

#9 ·  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()

*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

Share this post


Link to post
Share on other sites

#10 ·  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

#11 ·  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.

Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Share this post


Link to post
Share on other sites

#12 ·  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