Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

How to control an infinite loop script


  • Please log in to reply
3 replies to this topic
hodag
  • Members
  • 9 posts
  • Last active: Oct 14 2017 01:24 PM
  • Joined: 23 Jun 2011

I have a script that I want to loop for very long periods of time, but the number of cycles is undeterminable in advance so I can't use something like:

 

Loop, 100

{

Bunch of commands

}

 

because I don't know in advance if I need 100 loops, 500 loops, or some other number.  Of course I can create an infinite loop like this:

 

Top::

{

Bunch of commands

}

Goto, Top

 

The problem is that if I use the second syntax it will be spewing out "Sends" and mouse clicks so fast that it is hard to regain control of the computer without forcing a reboot.  Is there a way to nicely cancel the endless loop, similar to hitting a manual "Break" with a run-away procedural program, that will flush the pending commands and return control to the mouse and keyboard?

 



Oldman
  • Members
  • 2475 posts
  • Last active: Feb 18 2015 04:57 PM
  • Joined: 01 Dec 2013

There are plenty of example in this forum.

Here is another one. You can change the hotkeys to suit your needs.

Ctrl+F1 starts the loop. Ctrl+F2 stops the loop.

^F1::
toggle=1
While toggle
{
Bunch of commands
}
return

^F2::toggle=0
Esc::ExitApp

Si ton labeur est dur et que tes résultats sont minces, souviens toi du grand chêne qui avant n'était qu'un gland....comme toi ! (anonyme) ;)

L'art de lire, c'est l'art de penser avec un peu d'aide. (É. Faguet)

Windows 3.1. Collector's Edition.     (www.avaaz.org)


hodag
  • Members
  • 9 posts
  • Last active: Oct 14 2017 01:24 PM
  • Joined: 23 Jun 2011

Thanks for the reply.  I assume the script looks for a change in "toogle" state right after the } that encloses the command list and before looping back to the top?



RHCP
  • Members
  • 1228 posts
  • Last active: Apr 08 2017 06:17 PM
  • Joined: 29 May 2006

Before every loop iteration the expression ' toggle ' is evaluated. If true, the loop continues.