XIXI Posted May 15, 2008 Posted May 15, 2008 (edited) Well, I was in need of a timer, one that executed scripts after a certain time, sleep worked untill i had two functions that needed to be executed on diffrent times.. Also, i'm running this from Linux trough wine, so i can't manage to open the help file for autoit and the online document don't cover very much. I couldn't find any information on how to make objects/classes or dictionary arrays( arrays that look like $array['key'] ), So i used Global variables that have a prefix of at_, so the global variables look like; at_<nameoftimer>Run, at_<nameoftimer>RunI used a tiny little bit of sohfeyr s Timer function script?My email/msn is: aco@mostpointless.com so contact me if you got questions, or wish me to edit this post. Also I am happy if someone wants to develope this better/furtherSome feedback is welcome, thanks.expandcollapse popup#cs Contact the author at aco@mostpointless.com Function Delayrun() Return Values: 1 : Executed first argument 0 : Nothing done, continue Arguments: First argument: $function : What string to execute Second argument $getendtime : Where to get the time when it shall execute the first argument Description: This function checks if the time right now is bigger than the $endtime. If it has, it executes the script, return the integer 1, and continues the script. #ce Func delayrun($function, $getendtime) $endtime = Execute($getendtime) If API_GetTickCount() > $endtime Then Execute($function) Return 1 EndIf Return 0 EndFunc ;==>delayrun #cs Function Api_GetTickCount() This is not my self written function, so I'll skip to explain in detail what it does beside getting the system time(?) #ce Func API_GetTickCount() $t = DllCall("kernel32.dll", "int", "GetTickCount") Return $t[0] EndFunc ;==>API_GetTickCount #cs Function timerrun() Return Values: <0-999999> : This is the endtime, when the delayrun should do a timerrun('run') Arguments: First argument: $tmpString, this is similar to property in classes in other programming languages Selection of the first argument: $which = 'run', resets the time and executes the second argument $which = 'init', initiliaze the script, declaring the globals so we get no errors when trying to do $which = gettime $which = 'gettime', this makes the function return a value thats time when its allowed to execute the third argument Second argument: $which, this is the global name of the timer, for example if $which = <yourname>, then the function will create $at_<yourname>end and $at_<yourname>run global variables, to be able to track. Third argument: $what: default = ""(empty string) this determains what it shall execute when a $which = 'run' is used Fourth argument: $ms: default = 5000(integer), how many milliseconds from the time when executed/initilialized it shall execute Description: This is the biggest "function", it returns time, keeps track of what to run, when to run. #ce Func timerrun($tmpString, $which, $what = "", $ms = 5000) $prefix = "at_" $whichEnd = $prefix & $which & "end" $whichRun = $prefix & $which & "run" If $tmpString == "run" Then Assign($whichEnd, API_GetTickCount() + $ms, 2) Assign($whichRun, $what, 2) Execute(Eval($whichRun)) ElseIf $tmpString == "init" Then Assign($whichEnd, API_GetTickCount() + $ms, 2) Assign($whichRun, $what, 2) ElseIf $tmpString == "gettime" Then Return Eval($whichEnd) EndIf EndFunc ;==>timerrun #cs Below is only the test run, or examples, what ever you wish to call it #ce Func Test1() $Test1var = $Test1var + 1; ConsoleWrite("Timer1: " & $Test1var & @CRLF) EndFunc ;==>Test1 Func Test2() $Test2var = $Test2var + 1; ConsoleWrite("Timer2: " & $Test2var & @CRLF) EndFunc ;==>Test2 #cs Make the test variables global, so we don't get any trouble. #ce Global $Test1var = 0 Global $Test2var = 2 #cs here we initialize two timers, test1 and test2, test1 is assigned to execute Test1() in 400 milliseconds test2 is assinged to execute Test2() in 2000milliseconds #ce timerrun('init', 'test1', 'Test1()', 400) timerrun('init', 'test2', 'Test2()', 2000) #cs Start the looping so we can check times. Delayrun will execute the first argument if it has passed the time it gets from the second argument Well thats about it.. #ce While 1 delayrun("timerrun('run','test1','Test1()',400)", "timerrun('gettime','test1')") delayrun("timerrun('run','test2','Test2()',2000)", "timerrun('gettime','test2')") WEnd Edited May 15, 2008 by XIXI
weaponx Posted May 15, 2008 Posted May 15, 2008 Non-asynchronous is a double negative. Just say synchronous.
XIXI Posted May 15, 2008 Author Posted May 15, 2008 Non-asynchronous is a double negative. Just say synchronous.darn, thats true ^^
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now