linuspirus Posted August 27, 2017 Share Posted August 27, 2017 Hello, I'm kind of new to this programming entirely and I was wondering how would you go about creating a timer for example and have it tooltip every second while the rest of the script runs? I'm trying to find out how to run this function while the rest of the script continues to run ... timerStart() ... Func timerStart() For $i = 1 To 60 ToolTip($i & "/60", 200,200,"Time Remaining") Sleep(1000) Next EndFunc Link to comment Share on other sites More sharing options...
Fr33b0w Posted August 27, 2017 Share Posted August 27, 2017 Why don't you make separate script as timer and if not what should be the rest of the script? Because if you have Sleep commands or some time depending code, calling for function would be not so accurate... Link to comment Share on other sites More sharing options...
Developers Jos Posted August 27, 2017 Developers Share Posted August 27, 2017 Use Adlib commands to interrupt the regular process for timer purposes like you show here. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
linuspirus Posted August 27, 2017 Author Share Posted August 27, 2017 1 minute ago, Fr33b0w said: Why don't you make separate script as timer and if not what should be the rest of the script? Because if you have Sleep commands or some time depending code, calling for function would be not so accurate... Thanks for the quick reply. I would make it two separate scripts but I plan on compiling the script eventually :/ not sure if there's a way around it still? Link to comment Share on other sites More sharing options...
linuspirus Posted August 27, 2017 Author Share Posted August 27, 2017 7 minutes ago, Jos said: Use Adlib commands to interrupt the regular process for timer purposes like you show here. Jos Thanks for replying, Jos. I've tried these commands before and I'm not sure if I'm using them properally but I came up with this to better show what I'm trying to express AdlibRegister("timerStart", 0) For $x = 1 To 6 Beep(500,100) Sleep(2000) Next AdlibUnRegister("timerStart") Func timerStart() For $i = 1 To 10 ToolTip($i & "/10", 200,200,"Time Remaining") Sleep(1000) Next EndFunc I still want the beeps to go through while the timer is continuing to loop. This is just a hypothetical demo script but I'd still like to figure this out for other scripts :/ Link to comment Share on other sites More sharing options...
Developers Jos Posted August 27, 2017 Developers Share Posted August 27, 2017 (edited) That should be something like: (untested) AdlibRegister("timerStart", 1000) Global Counter=0 For $x = 1 To 6 Beep(500,100) Sleep(2000) Next AdlibUnRegister("timerStart") Func timerStart() counter += 1 ToolTip($i & "/10", 200,200,"Time Remaining") ; stop the timer after x counts if Counter > 10 then AdlibUnRegister("timerStart") EndFunc Jos Edited August 27, 2017 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
RTFC Posted August 27, 2017 Share Posted August 27, 2017 (edited) What you want is called multi-threading, a feature that AutoIt does not, nor ever will support. An alternative, feasible approach is multi-processing, which would entail running two (or more) separate scripts/executables, that if need be, can communicate with each other (search for IPC: inter-process communication). There are lots of ways of achieving this kind of set-up, from braindead simple to incredibly sophisticated. Any interrupt-based scheme (such as AdLib) suspends the main workflow until it returns. Edited August 27, 2017 by RTFC clarification My Contributions and Wrappers Spoiler BitMaskSudokuSolver BuildPartitionTable CodeCrypter CodeScanner DigitalDisplay Eigen4AutoIt FAT Suite HighMem MetaCodeFileLibrary OSgrid Pool RdRand SecondDesktop SimulatedAnnealing Xbase I/O Link to comment Share on other sites More sharing options...
linuspirus Posted August 27, 2017 Author Share Posted August 27, 2017 3 minutes ago, Jos said: That should be something like: (untested) AdlibRegister("timerStart", 1000) Global Counter=0 For $x = 1 To 6 Beep(500,100) Sleep(2000) Next AdlibUnRegister("timerStart") Func timerStart() counter += 1 ToolTip($i & "/10", 200,200,"Time Remaining") ; stop the timer after x counts if Counter > 10 then AdlibUnRegister("timerStart") EndFunc Jos Very interesting, thanks for solving my issue Link to comment Share on other sites More sharing options...
linuspirus Posted August 27, 2017 Author Share Posted August 27, 2017 3 minutes ago, RTFC said: What you want is called multi-threading, a feature that AutoIt does not, nor ever will support. An alternative, feasible approach is multi-processing, which would entail running two (or more) separate scripts/executables, that if need be, can communicate with each other (search for IPC: inter-process communication). There are lots of ways of achieving this kind of set-up, from braindead simple to incredibly sophisticated. Thanks for the information, I was wondering what it was actually called. Link to comment Share on other sites More sharing options...
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