Sign in to follow this  
Followers 0
Uten

TimerLib.

2 posts in this topic

Just a simple sample on a question asked rather often.

There are probably better samples in the forum. I have entered this for later reference.

;TimerLib.au3
;
#region - Timer
Global $TimerStorage[10][3]
Func TimerAdd($funcname, $ms)
   dbg("TimerAdd($funcname:=" & $funcname & ", $ms:=" & $ms)
   $ret = $TimerStorage[0][0] + 1
   $TimerStorage[$ret][0] = $funcname
   $TimerStorage[$ret][1] = $ms
   $TimerStorage[$ret][2] = 0
   $TimerStorage[0][0] = $ret
   Return $ret
EndFunc

Func TimerRemove($id)
   $TimerStorage[$id][0] = ""
   $TimerStorage[$id][1] = ""
   $TimerStorage[$id][2] = 0
EndFunc

Func TimerCheck()
   ;;;dbg("TimerCheck::$TimerGo:=" & $TimerGo)
      For $i = 1 to $TimerStorage[0][0]
         If $TimerStorage[$i][0] <> "" Then 
            If $TimerStorage[$i][2] = 0 Then 
               $TimerStorage[$i][2] = TimerInit()
            ElseIf TimerDiff($TimerStorage[$i][2]) >= $TimerStorage[$i][1] Then 
               ;;;dbg("Calling: " & $TimerStorage[$i][0])
               Call($TimerStorage[$i][0])
               $TimerStorage[$i][2] = TimerInit()
            EndIf
         EndIf
      Next 
EndFunc
#endregion - Timer
Func Main()
   HotKeySet("{ESC}", "Terminate")
   TimerAdd("A", 1000)
   TimerAdd("B", 300)
   TimerAdd("C", 33)

   AdLibEnable("TimerCheck", 25)
   While True
      sleep(10)
   WEnd
   Exit
EndFunc
Func Terminate()
   Exit
EndFunc
Func A()
   dbg("A Called")
EndFunc
Func B()
   dbg("B Called")
EndFunc
Func C()
   dbg("C Called")
EndFunc
Func dbg($msg, $line=@ScriptLineNumber, $err=@error, $ext=@extended)
   ConsoleWrite("(" & $line & ") := (" & $err & ")(" & $ext & ") " & $msg & @CRLF)
EndFunc
; ====================
Main()
Exit

Share this post


Link to post
Share on other sites



Hi,

This example seems partially inspired from my TimerLib (same name, same function names, etc...) but this one doesn't works because this is more complicated than it seems.

Please avoid sucking up other people's scripts with no added value (subtracted value I should say)...

Thanks in advance

Jérôme

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