Jump to content

Break a function


Recommended Posts

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.
Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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

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