Jump to content

Calling


Nachico
 Share

Recommended Posts

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPISys.au3>
#include <Timers.au3>
#Include <Date.au3>
#include <GuiEdit.au3>

Global $MIN

While 1
AdlibRegister("Check_DC", 20000)
WEnd


Func Check_DC()
    Local $MIN15
    If GetMapLoading() == 2 Or GetAgentExists(-2) == False Then DISCONNECTED()
    $MIN15 = $MIN + 15
    If $MIN15 <= @MIN Then
        Exit
    EndIf
EndFunc   ;==>CHECK_DC


Func DISCONNECTED()
    Local $LCHECK = False
    Local $LDEADLOCK = TimerInit()
    Do
        Sleep(20)
        $LCHECK = GETMAPLOADING() <> 2 And GETAGENTEXISTS(-2)
    Until $LCHECK Or TimerDiff($LDEADLOCK) > 5000
    If $LCHECK = False Then
        OUT("Disconnected!")
        OUT("Attempting to reconnect.")
        ControlSend(GETWINDOWHANDLE(), "", "", "{Enter}")
        $LDEADLOCK = TimerInit()
        Do
            Sleep(20)
            $LCHECK = GETMAPLOADING() <> 2 And GETAGENTEXISTS(-2)
        Until $LCHECK Or TimerDiff($LDEADLOCK) > 60000
        If $LCHECK = False Then
            OUT("Failed to Reconnect 1!")
            OUT("Retrying.")
            ControlSend(GETWINDOWHANDLE(), "", "", "{Enter}")
            $LDEADLOCK = TimerInit()
            Do
                Sleep(20)
                $LCHECK = GETMAPLOADING() <> 2 And GETAGENTEXISTS(-2)
            Until $LCHECK Or TimerDiff($LDEADLOCK) > 60000
            If $LCHECK = False Then
                OUT("Failed to Reconnect 2!")
                OUT("Retrying.")
                ControlSend(GETWINDOWHANDLE(), "", "", "{Enter}")
                $LDEADLOCK = TimerInit()
                Do
                    Sleep(20)
                    $LCHECK = GETMAPLOADING() <> 2 And GETAGENTEXISTS(-2)
                Until $LCHECK Or TimerDiff($LDEADLOCK) > 60000
                If $LCHECK = False Then
                    OUT("Could not reconnect!")
                    OUT("Exiting.")
                    ENABLERENDERING()
                    Exit 1
                EndIf
            EndIf
        EndIf
    EndIf
    OUT("Reconnected!")
    Sleep(5000)
EndFunc   ;==>DISCONNECTED

Hello! 

I hope this is in the right section, i have read the forum guidelines but they are never clear to me. 

I am trying to create a function "Check_DC" that checks every 20 seconds (AdlibRegister("Check_DC", 20000),  if the script is in a particular loading state (getmaploading) or an figure exists (GetAgentExists) and if so, it then will first call Disconnected() and after 15 min nothing changed then i want it to exit the script. 

What happens now it continues to spam exit the program before the 15 min check.   

Link to comment
Share on other sites

Hello.

@Min is an Autoit Macro returning the "minute-part-of-the-current-time".

I think what you are looking for is to "wait some 15 minutes"

 

Have a look at TimerInit() and TimerDiff()

 

CU, Rudi.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

12 minutes ago, Nine said:

Also having AdlibRegister into a loop seems highly suspicious, but cannot be totally sure since we don't have the full script.

Yeah, i realized that after posting too. There are many loops in the script. It jumps from loop to loop. The while loop is just for example it checks every 20 sec.  Posting the original loop would only be confusing since all functions communicate with an API. But my question, is there something wrong with the code itself? Or should this work in theory and i just have to find out the right "position" for it in the script?

Link to comment
Share on other sites

Like rudi said, using @min like you do is certainly not what you want to achieve.  Since you didn't make a runable script, it is hard for us to give you the exact solution.  Normally you should provide a snippet that we can run so we can test the script and give you alternative suggestions.

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...