mond1106 Posted November 3, 2016 Posted November 3, 2016 how do I break the loop if my program is stuck in it without exiting the whole program? i just want it to start from the beginning of the code here is my program While 1 $picture = "target.png" $result = _ImageSearch($picture,1,$x1,$y1,0,0) If $result = 1 Then Send("{4}") MouseClick("left",$x1,$y1,1,1) Sleep(2000) Do $picture2 = "status.png" $result2 = _ImageSearch($picture2,1,$x1,$y1,0,0) Send("{2}") Send("{1}") Until $result2 = 1 as you see if my program doesnt detect or see picture2 then the loop wont stop.
spudw2k Posted November 3, 2016 Posted November 3, 2016 I would do so by creating a global variable which is evaluated to see if the loop should continue and use a hotkey to set the global variables value. Something like this. Global $bEsc = False ;Define Global "state" Variable HotKeySet("{esc}", "_Esc") ;Set HotKey to Run _Esc function when Esc key is pressed ;.... Do If $bEsc = True Then ;At beginning of loop check $bEsc value and If True act on it $bEsc = False ;Reset $bEsc value ExitLoop ;Exit Loop EndIf Until ;...you get the idea? Func _Esc() ;Function to set $bEsc value to True $bEsc = True EndFunc Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF
mond1106 Posted November 3, 2016 Author Posted November 3, 2016 3 hours ago, spudw2k said: I would do so by creating a global variable which is evaluated to see if the loop should continue and use a hotkey to set the global variables value. Something like this. Global $bEsc = False ;Define Global "state" Variable HotKeySet("{esc}", "_Esc") ;Set HotKey to Run _Esc function when Esc key is pressed ;.... Do If $bEsc = True Then ;At beginning of loop check $bEsc value and If True act on it $bEsc = False ;Reset $bEsc value ExitLoop ;Exit Loop EndIf Until ;...you get the idea? Func _Esc() ;Function to set $bEsc value to True $bEsc = True EndFunc Hi is there a way that my program can automatically checked if its stuck in the loop?
spudw2k Posted November 3, 2016 Posted November 3, 2016 You'd have to define some sort of condition of what stuck means: been looping for so long? looped x many times? I'd say a timer is a reasonable way to go, but like I said, it's up to you to define a threshold that would mean stuck to you. ;More pseudo-code ;Create timer outside of loop Local $hTimer = TimerInit() ;Inside of Loop Do If TimerDiff($hTimer) > 30000 Then ;<- Timer measured in milliseconds - 30 seconds X 1000 milliseconds = 30,000 milliseconds $hTimer = TimerInit() ;Reset Timer ;do stuff EndIf Until 0=1 ;something mond1106 1 Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF
mond1106 Posted November 4, 2016 Author Posted November 4, 2016 5 hours ago, spudw2k said: You'd have to define some sort of condition of what stuck means: been looping for so long? looped x many times? I'd say a timer is a reasonable way to go, but like I said, it's up to you to define a threshold that would mean stuck to you. ;More pseudo-code ;Create timer outside of loop Local $hTimer = TimerInit() ;Inside of Loop Do If TimerDiff($hTimer) > 30000 Then ;<- Timer measured in milliseconds - 30 seconds X 1000 milliseconds = 30,000 milliseconds $hTimer = TimerInit() ;Reset Timer ;do stuff EndIf Until 0=1 ;something I think this timer would do the trick thank you.
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