Jump to content

Timers???


dassksnz
 Share

Recommended Posts

TimerInit() and TimerDiff() together works like a stop watch. TimerInit() starts the timer, TimerDiff() gives you the amount of time that has passed since TimerInit() was called.

For your project, a simple Sleep(5000) will work. (Sleep is in miliseconds)

So,

While 1
;do your thing
Sleep(5000);5 seconds
Wend

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

Check out HotKeySet() in the helpfile, there is an example there of how to create a pause key for your script.

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

Try this:

; Set Paused to false
Global $Paused = False

; Set the Pause hotkey to Ctrl + 1
HotKeySet("^1", "TogglePause")

; Start the timer
Global $TimeStart = TimerInit()

; Run forever
While 1
    If $Paused Then
        Do
        Until $Paused = False
    EndIf
    
    ; Check how long has passed
    $TimeElapsed = TimerDiff($TimeStart)
    
    ; Check if the time elapsed is longer than a minute (60000 milliseconds)
    If $TimeElapsed >= 60000 Then 
        
        ; Tell the user a minute has passed
        MsgBox(0, "", "A minute has passed")
        
        ; Reset the timer
        $TimeStart = TimerInit()
    EndIf
    
WEnd


Func TogglePause()
    If $Paused = False Then
        $Paused = True
        MsgBox(0, "", "Paused")
    Else
        $Paused = False
        MsgBox(0, "", "UnPaused")
        
        ; Reset the timer to stop it from triggering immediately after coming out of pause
        $TimeStart = TimerInit()
    EndIf
EndFunc

NiVZ

Link to comment
Share on other sites

TimerInit() and TimerDiff() together works like a stop watch. TimerInit() starts the timer, TimerDiff() gives you the amount of time that has passed since TimerInit() was called.

Don't really like this explanation as it suggest something thats not corrects.

- There is just one general cpu-timer running on your computer, and its running all the time. (Actually ... some cpu's don't have one but thats a different matter. + Ignoring potential multi core exception.)

- TimerInit() just picks up (and returns) the current time value of that cpu-timer at the moment TimerInit() is used.

- TimerDiff() will also pick up the current cpu-time value, and compare that new value to the other one that you put into TimerDiff(<OtherOlderCpuTimeValue>)). And returns the difference between those two values ... in Milliseconds. (1/1000sec)

Thats all.

Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

  • 5 months later...

Sample Timer Code

;4.25

local $dif1 ="00"

local $dif2 ="00"

local $dif3 ="00"

While 1

$begin = TimerInit()

sleep(1000)

$dif = (Round(TimerDiff($begin)/1000))

$dif1 = $dif1+$dif

if $dif1 = 60 Then

$dif1 = 0

$dif2=$dif2+1

if $dif2<10 Then

$dif2 = "0"&$dif2

Endif

if $dif2 = 60 Then

$dif1 = 0

$dif2 = 0

$dif3=$dif3+1

if $dif3<10 Then

$dif3 = "0"&$dif3

Endif

EndIf

EndIf

If $dif1 < 10 Then

$dif1 = "0"&$dif1

;MsgBox(4096,"",$dif1)

ConsoleWrite("*"&$dif3&"."&$dif2&"."&$dif1&@CRLF)

Else

ConsoleWrite("*"&$dif3&"."&$dif2&"."&$dif1&@CRLF)

EndIf

Wend

Link to comment
Share on other sites

Right ... stick to newer topic's if you don't want others to spot that you are just upping your post count.

... And learn how to use the available forum features, like, well, code tags perhaps.

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...