Chobyhy Posted August 14, 2007 Share Posted August 14, 2007 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 More sharing options...
Generator Posted August 14, 2007 Share Posted August 14, 2007 ExitLoop Link to comment Share on other sites More sharing options...
Chobyhy Posted August 14, 2007 Author Share Posted August 14, 2007 ExitLoopWhere would I place ExitLoopIf I place it in Func would it refer to the loop that is currently running? Link to comment Share on other sites More sharing options...
Achilles Posted August 14, 2007 Share Posted August 14, 2007 (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 August 14, 2007 by Piano_Man My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list] Link to comment Share on other sites More sharing options...
Achilles Posted August 14, 2007 Share Posted August 14, 2007 (edited) HotKeySet("{Home}", "_Stop") Send('Test') AdLibEnable('_SendTest', 5000) While 1 Sleep(1000) WEnd Func _SendTest() Send('Test') EndFunc Func _Stop() AdlibDisable() EndFuncThis would actually be more efficient EDIT: Tested the code and fixed it... Edited August 14, 2007 by Piano_Man My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list] Link to comment Share on other sites More sharing options...
smashly Posted August 14, 2007 Share Posted August 14, 2007 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 More sharing options...
Achilles Posted August 14, 2007 Share Posted August 14, 2007 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 More sharing options...
smashly Posted August 14, 2007 Share Posted August 14, 2007 expandcollapse popupHotKeySet("{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 More sharing options...
Chobyhy Posted August 14, 2007 Author Share Posted August 14, 2007 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 Link to comment Share on other sites More sharing options...
Achilles Posted August 14, 2007 Share Posted August 14, 2007 (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 August 14, 2007 by Piano_Man My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list] Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now