Sign in to follow this  
Followers 0
Chobyhy

Stopping Current Loop Question

10 posts in this topic

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?

Share this post


Link to post
Share on other sites



ExitLoop

Share this post


Link to post
Share on other sites

ExitLoop

Where would I place ExitLoop

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

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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]

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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]

Share this post


Link to post
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

Share this post


Link to post
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]

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

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]

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  
Followers 0