Jump to content

How to exit function in any time I want


Recommended Posts

Im trying to make a condition or any code that when I call by a key press or dont satisfact a condiction Exit function. I found a thread in forum that discuss it but dont understand too much. Can any one help ?

http://www.autoitscript.com/forum/index.ph...c=4380&st=0 <<<< Thread of discussion

Function to exit

Func AEMode1()
    
        MouseUp ("Right")
        Sleep (80)
        MouseMove($AE1_LX, $AE1_LY ,1)
        Call ("SkillBotAE")   ;============ I want verify here
        MouseMove($AE1_RX, $AE1_RY ,1)
        Call ("SkillBotAE")  ;============ I want verify here
        MouseMove($AE1_LUUX, $AE1_LUUY ,1)
        Call ("SkillBotAE")  ;============ I want verify here
        MouseMove($AE1_RUUX, $AE1_RUUY ,1)
        Call ("SkillBotAE")  ;============ I want verify here
        MouseMove($AE1_LDX, $AE1_LDY ,1)
        Call ("SkillBotAE")  ;============ I want verify here
        MouseMove($AE1_RDX, $AE1_RDY ,1)
        Call ("SkillBotAE")
        MouseMove($AE1_LUX, $AE1_LUY ,1)
        Call ("SkillBotAE")
        MouseMove($AE1_RUX, $AE1_RUY ,1)
        Call ("SkillBotAE")
        MouseMove($AE1_UX, $AE1_UY ,1)
        Call ("SkillBotAE")
        MouseMove($AE1_DX, $AE1_DY ,1)
        Call ("SkillBotAE")
EndFunc

Regards

GL

Link to comment
Share on other sites

Do you mean you want to verify if a condition is met, then go to a function, and if it's not, Exit?

And what condition is that?

Edited by BALA
[font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com
Link to comment
Share on other sites

Once this function started lets supose that this fuction will spend 5 minuts to finish. Passed 1 minute I want start another function pressing a hotkey. Then I ll have to wait 4 minutes pass to start function. I want when a press to start a function stop function that is running and start the new one.

Read the link of topic in post above and ull see what im talking about.

Look

Code to explain so s what I want.

HotkeySet ("{F5}", "On")
HotkeySet ("{F6}", "Off")

Func On()
Sleep (2000000000)
EndFunc

Func Off()
Send("ok")
EndFunc

While 1
    Sleep (1)
WEnd

Just for example... If Func On is running how to exit without wait sleep pass by ?

Thanks

Edited by stackover
Link to comment
Share on other sites

Just for example... If Func On is running how to exit without wait sleep pass by ?

At least for me it will automatically interrupt the sleep as soon as you push F6... Which means if you want to exit without waiting for the sleep just add something like this:

HotKeySet("{ESC}", "_Exit")
Func _Exit()
    Exit
EndFunc

Does this answer your question?

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Link to comment
Share on other sites

At least for me it will automatically interrupt the sleep as soon as you push F6... Which means if you want to exit without waiting for the sleep just add something like this:

HotKeySet("{ESC}", "_Exit")
Func _Exit()
    Exit
EndFunc

Does this answer your question?

I think stackover's talking about the sleep in the On function, not the one in the While loop.

I'm probably wrong, but I don't think you can do anything with your script while it's "asleep" since the entire script is paused.

Edited by BALA
[font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com
Link to comment
Share on other sites

What exactly is the point of the "On" function, since if it's just to wait, why don't you just take it out and use the While-Loop you have right now?

Edited by BALA
[font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com
Link to comment
Share on other sites

You can stick your sleep in to a loop, cut it in to a bunch of pieces (adding up to the total amount of time you want it to sleep), and stick a variable in it to allow you to exit your loop.

From your example...

HotKeySet("{F5}", "On")
HotKeySet("{F6}", "Off")
HotKeySet("{Esc}", "quit")

Global $exit

While 1
    Sleep(100)
WEnd

Func On()
    ConsoleWrite(@CRLF & 'in the loop')
    For $i = 1 To 60  ;cut your sleep up in to smaller pieces
        Sleep(1000)
        If $exit Then ExitLoop
    Next
    $exit = False
    ConsoleWrite(@CRLF & 'out of the loop')
EndFunc

Func Off()
    $exit = True
EndFunc

Func quit()
    Exit
EndFunc
Link to comment
Share on other sites

I think stackover's talking about the sleep in the On function, not the one in the While loop.

I'm probably wrong, but I think you can't do anything with your script while it's "asleep" since the entire script is paused.

But in the script that stackover posted if you run it and tell it to sleep it will sleep until the time is up OR until you push the the F6 button...

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Link to comment
Share on other sites

Look at my code ... This will show more clear what im trying.

Func On()
If @HotKeyPressed = '{F9}' Then
        $Mouselick= True
        Call ( "RequestOff" )
EndIf

If @HotKeyPressed = '{F10}' Then
    $ChangingAEBot = $ChangingAEBot + 1
        $AgilityElfs = True
    Call ( "RequestOff" )
EndIf
EndFunc

While 1

    If $AgilityElfs Then
        Switch $ChangingAEBot
            Case 1
                MouseUp ("Right")
                Sleep (80)
                MouseMove($AE1_LX, $AE1_LY ,1)
                Call ("SkillBotAE")             ;<<<<<<<<<<<<<<<<<<<< HERE <<<<<<<<<<<<<<<<<<<<<<
                MouseMove($AE1_RX, $AE1_RY ,1)
                Call ("SkillBotAE")             ;<<<<<<<<<<<<<<<<<<<< HERE <<<<<<<<<<<<<<<<<<<<<<
                MouseMove($AE1_LUUX, $AE1_LUUY ,1)
                Call ("SkillBotAE")             ;<<<<<<<<<<<<<<<<<<<< HERE <<<<<<<<<<<<<<<<<<<<<<
                MouseMove($AE1_RUUX, $AE1_RUUY ,1)
                Call ("SkillBotAE")             ;<<<<<<<<<<<<<<<<<<<< HERE <<<<<<<<<<<<<<<<<<<<<<
                MouseMove($AE1_LDX, $AE1_LDY ,1)
                Call ("SkillBotAE")             ;<<<<<<<<<<<<<<<<<<<< HERE <<<<<<<<<<<<<<<<<<<<<<
                MouseMove($AE1_RDX, $AE1_RDY ,1)
                Call ("SkillBotAE")             ;<<<<<<<<<<<<<<<<<<<< HERE <<<<<<<<<<<<<<<<<<<<<<
                MouseMove($AE1_LUX, $AE1_LUY ,1)
                Call ("SkillBotAE")             ;<<<<<<<<<<<<<<<<<<<< HERE <<<<<<<<<<<<<<<<<<<<<<
                MouseMove($AE1_RUX, $AE1_RUY ,1)
                Call ("SkillBotAE")             ;<<<<<<<<<<<<<<<<<<<< HERE <<<<<<<<<<<<<<<<<<<<<<
                MouseMove($AE1_UX, $AE1_UY ,1)
                Call ("SkillBotAE")             ;<<<<<<<<<<<<<<<<<<<< HERE <<<<<<<<<<<<<<<<<<<<<<
                MouseMove($AE1_DX, $AE1_DY ,1)
                Call ("SkillBotAE")
            Case 2
                MouseUp ("Right")
                Sleep (80)
                MouseMove($AE1_LX, $AE1_LY ,1)
                Call ("SkillBotAE")             ;<<<<<<<<<<<<<<<<<<<< HERE <<<<<<<<<<<<<<<<<<<<<<
                MouseMove($AE1_LUX, $AE1_LUY ,1)
                Call ("SkillBotAE")             ;<<<<<<<<<<<<<<<<<<<< HERE <<<<<<<<<<<<<<<<<<<<<<
                MouseMove($AE1_LUUX, $AE1_LUUY ,1)
                Call ("SkillBotAE")             ;<<<<<<<<<<<<<<<<<<<< HERE <<<<<<<<<<<<<<<<<<<<<<
                MouseMove($AE1_UX, $AE1_UY ,1)
                Call ("SkillBotAE")             ;<<<<<<<<<<<<<<<<<<<< HERE <<<<<<<<<<<<<<<<<<<<<<
                MouseMove($AE1_RUUX, $AE1_RUUY ,1)
                Call ("SkillBotAE")             ;<<<<<<<<<<<<<<<<<<<< HERE <<<<<<<<<<<<<<<<<<<<<<
                MouseMove($AE1_RUX, $AE1_RUY ,1)
                Call ("SkillBotAE")             ;<<<<<<<<<<<<<<<<<<<< HERE <<<<<<<<<<<<<<<<<<<<<<
                MouseMove($AE1_RX, $AE1_RY ,1)
                Call ("SkillBotAE")             ;<<<<<<<<<<<<<<<<<<<< HERE <<<<<<<<<<<<<<<<<<<<<<
                MouseMove($AE1_RUX, $AE1_RUY ,1)
                Call ("SkillBotAE")             ;<<<<<<<<<<<<<<<<<<<< HERE <<<<<<<<<<<<<<<<<<<<<<
                MouseMove($AE1_RDX, $AE1_RDY ,1)
                Call ("SkillBotAE")             ;<<<<<<<<<<<<<<<<<<<< HERE <<<<<<<<<<<<<<<<<<<<<<
                MouseMove($AE1_DX, $AE1_DY ,1)
                Call ("SkillBotAE")             ;<<<<<<<<<<<<<<<<<<<< HERE <<<<<<<<<<<<<<<<<<<<<<
                MouseMove($AE1_LDX, $AE1_LDY ,1)
                Call ("SkillBotAE")
            Case 3
                $ChangingAEBot = 0
        EndSwitch
    EndIf

WEnd

Look at arrows (;<< HERE <<<) if I hit F10 once .. $ChangingbotAE will be value 1 and Case 1 of Switch will start. If I decided hit F10 again $ChangingBotAE will set to 2 ... and will have to wait all Case 1 finish... How to jump to case 2 without wait Case 1 finish .. Is that.

In arrows I think that I have to do something to jump to case 2.

PS. SkillBotAE() only do mouse click for 3 secs... its not the problem

Edited by stackover
Link to comment
Share on other sites

I use call to call a function or my code will reach 10000000 lines in a simple script ..LOL ... if you can see i have the variable... BTW what about that command ContinueCase .. is that a command ?

Use myfunc() rather than Call('myfunc').

ContinueCase... you'd rather ask in the forum if it's a command instead of just looking it up in the help file?

Link to comment
Share on other sites

I already saw in documentations .. I think it wont help =[

I think that, rather than beating your head against the wall trying to find a way to do what you want while leaving your code how it is, you need to consider re-working the structure of your code.

for example

global $ACount=1
... 
;your code here
...

Switch $ChangingAEBot
            Case 1
              MouseUp ("Right")
              Sleep (80)
              Switch $ACount
                Case 1
                  MouseMove($AE1_LX, $AE1_LY ,1)
                  Call ("SkillBotAE")  
                Case 2
                  MouseMove($AE1_RX, $AE1_RY ,1)
                  Call ("SkillBotAE")    
;etc. until
                 Case Else
                   $ACount=0
                EndSwitch
                $ACount+=1

That way, everything is segmented and only one segment is run per loop. If you change the value of $ChangingAEBot then instead of running the next segment, it will skip to the next case. You will want to do this for Case 2 of Switch $ChangingAEBot as well. You may also want to reset $ACount to 0 when you change $ChangingAEBot from one value to another... thats up to you.

BTW, ContinueCase would probably actually do the job just as well, if you implemented it correctly.

And as a point of etiquette, DON'T bump your post multiple times in a single day. There is no need for that, and it only causes people who are more experienced to ignore the thread.

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