Jump to content
Sign in to follow this  
EndFunc

Break a function

Recommended Posts

EndFunc

I know you can set hot keys for certain things but I can seem to find out how can you break the currently running function without exiting the script? So if you have a function copying files and want to stop it how can you do that? I know in batch you can hit control c, but not sure how to set it in autoit with the hot key.

thanks


EndFuncAutoIt is the shiznit. I love it.

Share this post


Link to post
Share on other sites
EndFunc

Return?

I think that's what I might be looking for. Thanks, I will have to figure out how to use it though. I have not used it in any of my funtions yet.


EndFuncAutoIt is the shiznit. I love it.

Share this post


Link to post
Share on other sites
EndFunc

Insert this at the top of your script:

HotKeySet("^c", "Break")
Func Break()
    Exit
EndFunc
Will this stop whatever it's doing? I have a GUI and want it to go back to a ready to input state if I am running a function.

EndFuncAutoIt is the shiznit. I love it.

Share this post


Link to post
Share on other sites
lod3n

No, it will quit the whole script. Doing what you are describing is somewhat more difficult. You need to set a global variable and check for it while your function runs.

global $breaker = false
HotKeySet("^c", "Break")
Func Break()
    $breaker = true
EndFunc


;and then in your function:
Func MyFunc()
  while 1
    ; blah 
    ; blah 
    ; blah 
    ; blah 
    if $breaker = true then
        $breaker = false
        return
    endif
  wend
endfunc

Edited by lod3n

[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Share this post


Link to post
Share on other sites
EndFunc

No, it will quit the whole script. Doing what you are describing is somewhat more difficult. You need to set a global variable and check for it while your function runs.

global $breaker = false
HotKeySet("^c", "Break")
Func Break()
    $breaker = true
EndFunc
;and then in your function:
Func MyFunc()
  while 1
    ; blah 
    ; blah 
    ; blah 
    ; blah 
    if $breaker = true then
        $breaker = false
        return
    endif
  wend
endfunc
I will give that a shot and see what I come up with. Thanks

EndFuncAutoIt is the shiznit. I love it.

Share this post


Link to post
Share on other sites
magician13134

Return just bumps you out of a function, and (if told to do so) will store that value. IE:

$var = func(4)

Func func($i)
    $i = $i + 1
    return $i
EndFuncoÝ÷ Ûtß«Ú¯g£ª¹©lå8^±©r^Â+ajÉbf¡ØÆ­ÚºÚ"µÍÌÍÝH[Ê
B[È[Ê ÌÍÚJB    ÌÍÚHH    ÌÍÚH
ÈB]    ÌÎNÐR    ÌÌÎÉÌÎNÂ[[

'$var' now equals 'BLAH!'.

Play around with it...

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
Sign in to follow this  

×