Jump to content

Exit running functions


Recommended Posts

I'm using the Timer functions MAGS has posted here, and they work great for the most part.

The problem I have is that other functions will be running when a timed function is set to execute and the timed function will be skipped, or sometimes only partially run.

Is there a way to force the other function(s) to stop (or even pause) executing when the timed function comes due?

This is just a script that is running in the background, so there isn't any keypress or button press to check for. I've seen posts here regarding @error checking, but I don't know if that is appropriate, and I couldn't find anything in the help file about it either.

Link to comment
Share on other sites

I'm using the Timer functions MAGS has posted here, and they work great for the most part.

The problem I have is that other functions will be running when a timed function is set to execute and the timed function will be skipped, or sometimes only partially run.

Is there a way to force the other function(s) to stop (or even pause) executing when the timed function comes due?

This is just a script that is running in the background, so there isn't any keypress or button press to check for. I've seen posts here regarding @error checking, but I don't know if that is appropriate, and I couldn't find anything in the help file about it either.

If this function is always supposed to run at a set time, you could call it with AdlibEnable, and then set the poll time to the time you need.

Nomad :D

Link to comment
Share on other sites

By a "set time", are you meaning at exactly 10:15pm, or do you mean every 90 seconds? I've got a few different timers running at, say, every 127 seconds (127000 ms for the timer), 34 seconds, and 600 seconds.

I'll take a look at AdlibEnable and see if I can make any sense out of it. If it worked for me, would it eliminate the use of MAGS' timer functions?

(After the last time you helped me muddle my way through your memory functions, I thought I might not ever hear from you again. :"> And, by the way, they're working perfectly. Thanks again.)

*** Edit ***

Wow! That sounds like the perfect thing. And I wouldn't need to call the timer functions anymore. According to their example:

AdlibEnable("myadlib")
;...
Exit

Func myadlib()
    If WinActive("Error") Then
        ;...
    EndIf
EndFuncoÝ÷ Ø&§!ÈZ¢¶Ú,¢g­)à)¶¬jëh×6If $SayHi = 1 Then
    AdlibEnable("SayHi", 120000)
EndIf


Func SayHi()
    Send ("hi")
    Sleep (2000)
    Send ("bye")
EndFunc

Is that all it takes?

One more thing. If I have multiple "timers" that are scheduled to go off at the same time, would they just stack up behind each other and wait their turn? I'm thinking they can't all be due at the same time since they all start milliseconds or seconds after each other. But even so, I'm thinking they'll still just wait their turn if one AdlibEnable is currently running.

One more "one more thing". Is an AdlibDisable required anywhere?

*** 2nd Edit ***

Well, I have one AdlibEnable running successfully. But I can't seem to have two running. It just seems to remember the last one that was defined. Is it only possible to have one running at a time?

Edited by Styler001
Link to comment
Share on other sites

  • Moderators

AdlibEnable('_MultipleAdlibs', 10)

While 1
    Sleep(1000)
WEnd

Func _MultipleAdlibs()
    Function1()
    Function2()
EndFunc

Func Function1()
    MsgBox(64, 1, 'Function1')
EndFunc

Func Function2()
    MsgBox(64, 2, 'Function2')
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

You can only have one Adlib function active at a time. If you call the function a second time, you overwrite the first.

I was afraid of that. That kind of limits my options. But Sm0ke's suggestion gives me a path to consider. The only problem I see is that I'll only be able to use multiples if they are all the same duration. Unfortunately, I don't think I have any that fit that bill. They're pretty much all different.

Thanks, Sm0ke. I'll play around with that and see if I can come up with some workaround. Right now I don't see one, but maybe looking at this again with a fresher mind will help.

Link to comment
Share on other sites

One solution (and I don't know if it'd work) would be to use a separate function that would monitor the use of AdlibEnable commands and start the next one up based off of time differences. This is all "on-the-fly" thinking, so forgive me if it seems convoluted. I can just see this taking up alot of lines of coding the way I'm envisioning it if there gets to be too many "timers". As it is, I think there will only be 3 or 4 timed functions. Also, please forgive the "noobish" look of this.

$Function1Used = 1
$Function2Used = 1
$Function1Time = 120000
$Function2Time = 180000

If $Function1Used = 1 Then 
  AdlibEnable ("Function1", $Function1Time)
ElseIf $Function2Used = 1 Then
  AdlibEnable ("Function2", $Function2Time)
EndIf

Func Function1()
  .
  .
  If $Function2Used = 1 Then AdlibEnable ("Function2", $Function2Time - $Function1Time)
EndFunc

Func Function2()
  .
  .
  If $Function1Used = 1 Then AdlibEnable ("Function1", $Function2Time - $Function1Time)
EndFunc

I know this is just a best case scenario. Of course, there would have to be checks for if Function1 isn't used so Function2 would still run if it was used. As well as checks for any other timed functions. As well as for running Function1 again before Function2 if Function1's delay would expire again before Function2 was set to execute. And others I'm probably not seeing at this time.

Man, if this is something you guys think might work, it's going to get confusing. And I can foresee the timings starting to get thrown off little by little each time an AdlibEnable is called, since the timing wouldn't be true to the original start of it all. And I would have to have the functions called in order of lowest time to highest.

This is about the only solution I can think of. So if you guys have any better suggestions, I'm eager to hear them.

Link to comment
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
 Share

  • Recently Browsing   0 members

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