Jump to content

Recommended Posts

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

 

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

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?

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

  • Developers
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

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

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

 

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.

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
  • Recently Browsing   0 members

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