pecas Posted March 5, 2008 Posted March 5, 2008 I use a script similar to this: While 1 If Not (my conditions are true) Then Sleep(1000) Else While 1 (My Code Here) If (timer expired) Then ExitLoop EndIf WEnd EndIf WEnd The script is made to run 24/7, thus the main infinite loop (I have a Hotkeyset to stop it). The second loop inside repeats the code until a timer expires, and then Exits to the main loop again. Now my problem: once in a while, the script gets stuck inside the secondary loop. This depends on reasons outside the script that can't be changed. I found a suitable solution to terminate the script through another script, which checks the conditions, and smoothly terminates everything. But since I want my main script to run 24/7, I would love to have the ability to send from outside an "ExitLoop" command, so that it would restart from the main loop. Unfortunately, you can't use ExitLoop outside of a loop, and this prevents me to use a HotkeySet, or GUI event which refer to an external Function like this: Func _ExitLoop ExitLoop EndFunc Suggestions?
Siao Posted March 5, 2008 Posted March 5, 2008 (edited) Unfortunately, you can't use ExitLoop outside of a loop, and this prevents me to use a HotkeySet, or GUI event which refer to an external Function like this: Func _ExitLoop ExitLoop EndFunc Nothing prevents you from doing this: Global $fExitLoop While 1 $fExitLoop = 0 If Not (my conditions are true) Then Sleep(1000) Else While 1 (My Code Here) If (timer expired) Or $fExitLoop Then ExitLoop EndIf WEnd EndIf WEnd Func _ExitLoop() $fExitLoop = True EndFunc And how you trigger that _ExitLoop is up to you. For example, if you really have to do it from another script, register a message in your main app $hGui = GUICreate("Main app", 100, 100) GUIRegisterMsg(0x8123, '_ExitLoop');$WM_APP+somenumber and then in that other script, do $hWnd = WinGetHandle("Main app") If Not @error Then DllCall('user32.dll', 'int', 'PostMessage', 'hwnd', $hWnd, 'uint', 0x8123, 'wparam', 0, 'lparam', 0) Edited March 5, 2008 by Siao "be smart, drink your wine"
pecas Posted March 5, 2008 Author Posted March 5, 2008 Nothing prevents you from doing this: Global $fExitLoop While 1 $fExitLoop = 0 If Not (my conditions are true) Then Sleep(1000) Else While 1 (My Code Here) If (timer expired) Or $fExitLoop Then ExitLoop EndIf WEnd EndIf WEnd Func _ExitLoop() $fExitLoop = True EndFunc This won't solve my problem, because my main script gets stuck in (My Code Here) part... when it gets regularly to the If, (timer expired) works correctly, so there's no need to force an ExitLoop. I'll try your second suggestion, as soon as I have time today. I never used DllCall function, so will have to do some homework first. Will let you know if it solved my issue. Many thanks for your answer.
BrettF Posted March 5, 2008 Posted March 5, 2008 Couldn't you use Env Vars and a Adlib Loop?? Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
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