linuspirus

Loop something while running something else

9 posts in this topic

#1 ·  Posted

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

 

Share this post


Link to post
Share on other sites



#2 ·  Posted

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... 

Share this post


Link to post
Share on other sites

#4 ·  Posted

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?

Share this post


Link to post
Share on other sites

#5 ·  Posted

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 :/

Share this post


Link to post
Share on other sites

#6 ·  Posted (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 by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

What you want is called multi-threading, a feature that AutoIt does not, nor ever will support.:no: 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.:yes: Any interrupt-based scheme (such as AdLib) suspends the main workflow until it returns.

Edited by RTFC
clarification

Share this post


Link to post
Share on other sites

#8 ·  Posted

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 :)

 

Share this post


Link to post
Share on other sites

#9 ·  Posted

3 minutes ago, RTFC said:

What you want is called multi-threading, a feature that AutoIt does not, nor ever will support.:no: 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.:yes:

Thanks for the information, I was wondering what it was actually called.

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