Jump to content

Adlib failsafe function -> restart script


scenia
 Share

Recommended Posts

Hi!

I have the following (simplified) script, which is supposed to execute repeating tasks in different applications, checking the current state through specific pixels and thus making sure it's correctly doing its job:

HotKeySet("{F5}", "Go") ; Hitting F5 will start the bot
HotKeySet("{F7}", "Terminate") ; Hitting F7 will shut the bot down
 
Global $start = False ; We no start yet
 
Do
 Sleep(100)
Until $start ; Starting hotkey was hit, let's go!
 
AdlibRegister("WinActiveFailSafe", 60000) ; check each minute if window is still active to catch crashes
 
While 1 ; this will be repeated endlessly, until the Terminate function is executed
 ; do some UDFs
 While Not(PixelCheck(374,371,0x005067,5))
  ; some UDFs again
  Do
   Sleep(100) ; waiting
  Until PixelCheck(706,661,0xffffd1,20)
  ; more UDFs
 WEnd
WEnd ; redo from start
 
Func Go() ; starts the bot
 $start = True
EndFunc
 
Func Terminate() ; shut the bot down
 Exit
EndFunc
 
Func PixelCheck($x, $y, $color, $tolerance = 0) ; check if a pixel has specified color
 ; bla
EndFunc
 
; other UDFs
 
Func WinActiveFailSafe() ; failsafe for client crashes
 If WinActive("selectedprogram") Then Return ; everything's fine
 WinWaitActive("selectedprogram") ; wait for program to restart
 ; re-initialize bot
EndFunc
Now my problem comes with the failsafe function.

If the client did crash, it will restart automatically, the failsafe function will wait for it and return everything to the starting state. However, the script will then continue at whichever point it was interrupted by the Adlib function.

Since several of the UDFs lock the script, waiting for a specific pixel (I left a few examples in the snippet above), I need the script to restart from the while 1-statement.

Is there any other way than setting a parameter and checking for it in every single line of my script? There is no goto any more and ExitLoop or ContinueLoop don't work from inside a function... I don't want to add 200 "If $restart Then ContinueLoop" lines to the script, aside from the fact this will still leave room for inefficiency because some lines just take their while to be executed...

Edited by scenia
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...