Jump to content

Stopping Current Loop Question


Recommended Posts

Which function allows me to stop the loop in the middle of it if the condition changed?

For example

HotKeySet("{Home}", "stop")

While $var = 1
Send("Test")
Sleep(5000)
Send("Test")
WEnd

Func stop()
$var = 0
EndFunc

How do I make it so that when $var is changed to 0, it stops the loop without finishing it first?

Link to comment
Share on other sites

Where would I place ExitLoop

If I place it in Func would it refer to the loop that is currently running?

HotKeySet("{Home}", "stop")

While $var = 1
If $var = 0 then Exit
Send("Test")
Sleep(5000)
If $var = 0 then Exit
Send("Test")
WEnd

Func stop()
$var = 0
EndFunc
Edited by Piano_Man
My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Link to comment
Share on other sites

HotKeySet("{Home}", "_Stop")

Send('Test') 

AdLibEnable('_SendTest', 5000) 

While 1 
    Sleep(1000) 
WEnd

Func _SendTest() 
    Send('Test')
EndFunc

Func _Stop()
    AdlibDisable()
EndFunc
This would actually be more efficient

EDIT: Tested the code and fixed it...

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

HotKeySet("{Home}", "stop")
Global $var = 1

While $var = 1
    Send("Test")
    If $var = 0 Then ExitLoop
    Sleep(5000)
WEnd

Func stop()
    $var = 0
EndFuncoÝ÷ Ù:&jG¢¶Ê2¢êÞÆ+f¢·«zÊhȯ{*.r¥vf¤zØ^²W¦ÉW«jwZr·­Á秲W¥èºÚ"µÍÝÙ^TÙ]
    ][ÝÞÒÛY_I][ÝË ][ÝÜÝÜ  ][ÝÊBÛØ[    ÌÍÝHBÚ[H    ÌÍÝHBTÙ[
    ][ÝÕÝ    ][ÝÊBRY   ÌÍÝH[^]ÛÜTÛY
L
BRY ÌÍÝH[^]ÛÜTÛY
L
BRY ÌÍÝH[^]ÛÜTÛY
L
BRY ÌÍÝH[^]ÛÜTÛY
L
BRY ÌÍÝH[^]ÛÜTÛY
L
BRY ÌÍÝH[^]ÛÜÑ[[ÈÝÜ

BIÌÍÝH[[

Cheers

Link to comment
Share on other sites

And your fifth option:

HotKeySet("{Home}", "_Stop")

$exit = False
$timer = TimerInit() 

Send('Test')

While $exit = False
    If TimerDiff($timer) > 5000 then 
        Send('Test') 
        $timer = TimerInit() 
    EndIf
WEnd

Func _Stop()
    $exit = True
EndFunc
My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Link to comment
Share on other sites

HotKeySet("{Home}", "stop")
Global $var = 1

While $var = 1
    Send("Test")
    If $var = 0 Then ExitLoop
    Sleep(5000)
WEnd

Func stop()
    $var = 0
EndFuncoÝ÷ Ù:&jG¢¶Ê2¢êÞÆ+f¢·«zÊhȯ{*.r¥vf¤zØ^²W¦ÉW«jwZr·­Á秲W¥èºÚ"µÍÝÙ^TÙ]
    ][ÝÞÒÛY_I][ÝË ][ÝÜÝÜ  ][ÝÊBÛØ[    ÌÍÝHBÚ[H    ÌÍÝHBTÙ[
    ][ÝÕÝ    ][ÝÊBRY   ÌÍÝH[^]ÛÜTÛY
L
BRY ÌÍÝH[^]ÛÜTÛY
L
BRY ÌÍÝH[^]ÛÜTÛY
L
BRY ÌÍÝH[^]ÛÜTÛY
L
BRY ÌÍÝH[^]ÛÜTÛY
L
BRY ÌÍÝH[^]ÛÜÑ[[ÈÝÜ

BIÌÍÝH[[oÝ÷ Ø(^z»v+@az¶©¦ºrâêÈ+L¢·®'§v¨§jëh×6HotKeySet("{Home}", "stop")
Global $var = 1, $begin = TimerInit()

While $var = 1
    Sleep(10)
    If TimerDiff($begin) >= 5000 Then
        Send("Test")
        $begin = TimerInit()
    EndIf
    If $var = 0 Then ExitLoop
WEnd

Func stop()
    $var = 0
EndFunc

Link to comment
Share on other sites

Hmm thats abit of trouble. Seeing as how I will have over few hundred lines in this loop. I guess the only perfect way to end it is Exit

Well, you could try a different approach.

Add something like this into your the beginning of your code:

AdLibEnable('_CheckVar', 250)

and then the function

Func _CheckVar() 
If $var = 0 then Exit 
EndFunc

What this code will is check every quarter of a second if $var has been made 0, if it has it exits.

This checks even if your main loop is in the middle of sleeping.

Does this solve your problem?

EDIT: WAY EASIER SOLUTION

HotKeySet("{Home}", "stop")

While 1
Send("Test")
Sleep(5000)
Send("Test")
WEnd

Func stop()
Exit
EndFunc

This way you don't need any variable at all...

Edited by Piano_Man
My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
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...