Jump to content


Photo

StopAll


  • Please log in to reply
21 replies to this topic

#1 x79animal

x79animal
  • Members
  • 1021 posts

Posted 22 December 2010 - 04:04 AM

[example] If i had a had a simple loop

loop {
Send Hello
Sleep 500
}

[as far as i am aware] The only way to stop the loop and have the script not exit, is using Reload. Allthough that has to re-open the script which is visually annoying (icon moves) and if you accidentally hold down a button set as reload it crashes your computer [even if the script has singleinstance force on]

So i wish for

F1::StopAll


#2 MasterFocus

MasterFocus
  • Moderators
  • 4130 posts

Posted 22 December 2010 - 12:31 PM

Why not While?
While ( ctrlVar <> 1 )
{
  ToolTip, Hello
  Sleep, 150
}

F1:: ctrlVar := 1


#3 x79animal

x79animal
  • Members
  • 1021 posts

Posted 22 December 2010 - 03:25 PM

the loop was just an example, i want to stop all timers, loops, running threads & anything else

#4 Ace Coder

Ace Coder
  • Members
  • 362 posts

Posted 23 December 2010 - 09:46 PM

F1::Pause
:?: :?:

Or:
LoopLabel:
loop 
{
   Send Hello
   Sleep 500
}
Return

SomeLabel:
Return ;Used by the F1 hotkey via GoTo, meaning it won't Return anywhere, but simply wait around

F1::GoTo,SomeLabel


#5 Lexikos

Lexikos
  • Administrators
  • 8845 posts

Posted 24 December 2010 - 12:01 AM

When F1 is pressed with Ace Coder's second example, it does this:
[*:5nmc67vd]Interrupt the loop, starting a new thread.
[*:5nmc67vd]Go to SomeLabel.
[*:5nmc67vd]Return, finishing the F1 hotkey's thread.
[*:5nmc67vd]Resume the loop.Pointless... F1::return has the same effect.

#6 fragman

fragman
  • Members
  • 1591 posts

Posted 24 December 2010 - 01:44 AM

Just use a variable telling your timers/loops/hotkeys not do do anything. Alternatively, deactivate all running timers and use #if conditions in AHK_L.

#7 Tuncay

Tuncay
  • Members
  • 1943 posts

Posted 24 December 2010 - 09:18 AM

I would implement this way:
Loop
{
    IfEqual, STOPALL, 1, Break
    Send Hello
    Sleep 500
}
Copy the STOPALL-check at some different positions in the loop (and all other loops), including at the start. For example before any function call starts, which is very time consuming.

#8 x79animal

x79animal
  • Members
  • 1021 posts

Posted 24 December 2010 - 12:51 PM

Copy the STOPALL-check at some different positions in the loop (and all other loops), including at the start. For example before any function call starts, which is very time consuming.


I would have to put it inbetween every line in my script, because otherwise id i pressed the button mid-thread the thread would still finish. which is not ideal

#9 fragman

fragman
  • Members
  • 1591 posts

Posted 24 December 2010 - 01:17 PM

You should put the check at the places where the script interacts with other programs/files. It usually doesn't hurt if it's doing a few calculations or something like that.

#10 x79animal

x79animal
  • Members
  • 1021 posts

Posted 24 December 2010 - 03:52 PM

On an unrelated note, i've found out how Pause works

f4::
#MaxThreads 0 ;meh
#MaxThreads 1
sleep 10000 ;paused for duration
#MaxThreads 10 ;starts whatever it was doing again
return

8)

#11 MasterFocus

MasterFocus
  • Moderators
  • 4130 posts

Posted 24 December 2010 - 05:21 PM

x79animal, plase notice that

Up to two of the following types of threads may be created even when #MaxThreads has been reached: A hotkey, hotstring, OnClipboardChange, or GUI event if the first line of its subroutine is ExitApp, Pause, Edit, Reload, KeyHistory, ListLines, ListVars, or ListHotkeys. Also, the OnExit subroutine will always launch regardless of how many threads exist.



#12 Guests

  • Guests

Posted 26 December 2010 - 02:43 AM

Jumps to the specified label and continues execution.

Meaning GoTo should not return to where it was called from, whereas GoSub does return to where it came from. Or is the documentation misleading?

#13 Lexikos

Lexikos
  • Administrators
  • 8845 posts

Posted 26 December 2010 - 03:40 AM

GoTo and GoSub don't return anywhere. That's what Return does. GoTo jumps to the specified label and continues execution; in Ace Coder's example, continuing execution means executing the next command (Return), which tells it to return from GoSub.

#14 tank

tank
  • Members
  • 4106 posts

Posted 26 December 2010 - 01:43 PM

so again i ask the same question Ace_coder implied
is there somer eason not to use pause?

#15 adabo

adabo
  • Members
  • 361 posts

Posted 26 December 2010 - 04:22 PM

+1 for the wishlist.