Jump to content
Sign in to follow this  
J0ker

AdlibEnable Error

Recommended Posts

Is this what your trying to do??

Global $pos, $Timestack
Global $bStuck = False
Global $TIMESTAMP;
Global $WAIT = 300;
;--------------------------------------------------------------------------
Start()
Exit
;--------------------------------------------------------------------------

Func Start()
    Local $restarts = 0
    AdlibEnable("ScriptStuck", 750)
    Do
        $bStuck = False
        TrayTip("Stuck", "Restarts " & $restarts, 10)
        $pos = MouseGetPos()
        BigLoop()
        $restarts += 1
        If $restarts > 4 Then $bStuck = False;Let's get out of here
    Until ($bStuck = False)
    AdlibDisable()
EndFunc   ;==>Start

Func BigLoop()
    While 1
        Sleep(500)
        ;; I'm a big azz loop
        If $bStuck Then Return
    WEnd
EndFunc   ;==>BigLoop

Func ScriptStuck()
    ToolTip("Time:      " & $Timestack, 0, 13)
    Local $var_2 = MouseGetPos()
    If IsArray($var_2) And IsArray($pos) Then
        If $pos[0] <> $var_2[0] Or $pos[1] <> $var_2[1] Then
            $pos = $var_2
            $Timestack = 0
        Else
            If TimerDiff($TIMESTAMP) > $WAIT Then
                $TIMESTAMP = TimerInit()
                If $Timestack > 1 Then TrayTip("", "", 0); shut the tip off
                If $Timestack < 10 Then
                    $Timestack = $Timestack + 1
                Else
                    $bStuck = True
                    $Timestack = 0
                EndIf
            EndIf
        EndIf
    EndIf
    ToolTip("Time:      " & $Timestack, 0, 13)
EndFunc   ;==>ScriptStuck

Every 10 timestacks, the flag $bStuck is set true. The BigLoop returns when it sees this flag. Start recalls BigLoop.

eltorro

Share this post


Link to post
Share on other sites

I will test it to see if it work in my script, but there should be no loop in the Start() functions. My start function is where the script check for all errors, if there's no error then it jump to Main() ( the big loop).

EDIT: I had to change the code to fit in my script but after some modifications its aint working.

;Hotkeys
HotKeySet("{ENTER}", "Try") ; Run the Script when ENTER is pressed



;Variables

Global $pos, $Timestack
Global $bStuck = False
Global $TIMESTAMP;
Global $WAIT = 300;



While 1
    Sleep(100)
WEnd

    
Func ScriptStuck()
    ToolTip("Time:      " & $Timestack, 0, 13)
    Local $var_2 = MouseGetPos()
    If IsArray($var_2) And IsArray($pos) Then
        If $pos[0] <> $var_2[0] Or $pos[1] <> $var_2[1] Then
            $pos = $var_2
            $Timestack = 0
        Else
            If TimerDiff($TIMESTAMP) > $WAIT Then
                $TIMESTAMP = TimerInit()
                If $Timestack < 10 Then
                    $Timestack = $Timestack + 1
                Else
                    $bStuck = True
                    $Timestack = 0
                    EndIf
                EndIf
        EndIf
    EndIf
    ToolTip("Time:      " & $Timestack, 0, 13)
EndFunc   ;==>ScriptStuck

Func Try()

Local $restarts = 0
    AdlibEnable("ScriptStuck", 3000)
    Do
        $bStuck = False
        $pos = MouseGetPos()
        Start()
        $restarts += 1
        If $restarts > 4 Then $bStuck = False;Let's get out of here
    Until ($bStuck = False)
    AdlibDisable()
    
EndFunc

Func Start()
    

    HotKeySet("{ENTER}")

    If $Pause1 = 1 Then
    Else
        $Pause1 = $Pause1 + 1
    EndIf

    $size = WinGetClientSize('')
    If $size[0] = 1024 And $size[1] = 768 Then
        
    Else
        MsgBox(0,"Resolution Error ","Internet Explorer 7 is not in full screen mode   Or   Your screen's resolutions are not 1024x768 pixels.")
        Sleep(50)
        Exit
    EndIf
    

    ; Level Setting
    If $Level < 1 OR $Level > 29 then
        MsgBox(0,"Level Error ","Make sure to fill the config.ini correctly ")
        Sleep(50)
        Exit
    EndIf
    
    

    Sleep(1000)

    MouseClick ( "left" , 525, 215 , 1 , 3  )
    Sleep(1500)


    MouseClick ( "left" , 525, 215 , 1 , 3  )
    Sleep(1000)
    

    Main()
EndFunc ;==> Start


Func Main()
    
    While 1
;blablabla
If $bStuck Then Return
Wend
Edited by J0ker

Share this post


Link to post
Share on other sites

The BigLoop returns when it sees this flag.

It wont work because I cannot put this statement everywhere. I need to have something that act as an external function. It wont work if the script have to reach the flag to restart.

Share this post


Link to post
Share on other sites

It wont work because I cannot put this statement everywhere. I need to have something that act as an external function. It wont work if the script have to reach the flag to restart.

I've been running this script for about 30 45 mins now.:

;Variables
Global $Pause1
Global $pos, $Timestack
Global $bStuck = False
Global $TIMESTAMP;
Global $WAIT = 1000;
;Hotkeys
HotKeySet("{ENTER}", "Try") ; Run the Script when ENTER is pressed



While 1
    Sleep(100)
WEnd

   
Func ScriptStuck()
    ToolTip("Time:      " & $Timestack, 0, 13)
    Local $var_2 = MouseGetPos()
    If IsArray($var_2) And IsArray($pos) Then
        If $pos[0] <> $var_2[0] Or $pos[1] <> $var_2[1] Then
            $pos = $var_2
            $Timestack = 0
        Else
            If TimerDiff($TIMESTAMP) > $WAIT Then
                $TIMESTAMP = TimerInit()
                If $Timestack < 10 Then
                    $Timestack = $Timestack + 1
                Else
                    $bStuck = True
                    $Timestack = 0
                    EndIf
                EndIf
        EndIf
    EndIf
    ToolTip("Time:      " & $Timestack, 0, 13)
EndFunc   ;==>ScriptStuck

Func Try()

Local $restarts = 0
    AdlibEnable("ScriptStuck", 300); leave this at 300, the $WAIT value effects the Timestack.
    Do
        $bStuck = False
        $pos = MouseGetPos()
        Start()
        $restarts += 1
        If $restarts > 4 Then $bStuck = False;Let's get out of here
    Until ($bStuck = False)
    AdlibDisable()
     MsgBox(0,"Stuck","This Loop has restarted "&$restarts -1&" times")
Exit
EndFunc

Func Start()
   

    HotKeySet("{ENTER}")

    If $Pause1 = 1 Then
    Else
        $Pause1 = $Pause1 + 1
    EndIf

;~     $size = WinGetClientSize('')
;~     If $size[0] = 1024 And $size[1] = 768 Then
;~        
;~     Else
;~         MsgBox(0,"Resolution Error ","Internet Explorer 7 is not in full screen mode   Or   Your screen's resolutions are not 1024x768 pixels.")
;~         Sleep(50)
;~         Exit
;~     EndIf
 

;~     ; Level Setting
;~     If $Level < 1 OR $Level > 29 then
;~         MsgBox(0,"Level Error ","Make sure to fill the config.ini correctly ")
;~         Sleep(50)
;~         Exit
;~     EndIf
   
   

    Sleep(1000)

    MouseClick ( "left" , 525, 215 , 1 , 3  )
    Sleep(1500)


    MouseClick ( "left" , 525, 215 , 1 , 3  )
    Sleep(1000)
   

    Main()
EndFunc ;==> Start


Func Main()
   
While 1
;blablabla
sleep(100)
If $bStuck Then Return
Wend
EndFunc

If I move the mouse the timer restarts. If I let it sit, the message box pops up and exits.

What is the underlying cause of your script "Being Stuck"?

Can you post the whole script?

It sounds like what you want is a Goto statement, and that isn't possible nor good programming practices.

What is the underlying cause of your script "Being Stuck"? Maybe the focus should be on that instead?

Eltorro

Edited by eltorro

Share this post


Link to post
Share on other sites

I will try to explain what happen in my script the best as I can. My script is doing all his actions on a website. On this website , theres some loading time between the pages. If for a reason, the loading time take more time then what I have expected in my code then the script wont be able to continue.

My script is all based on pixelgetcolor, so if theres a delay between the pages loading then the color that it supposed to be at (x,y) coordinates wont be the same as what I have written in my script. The mouse will be "stuck", it wont move because it cannot find the good color.

Ex:

Func Main()
   
While 1

MouseClick ( "left" , 525, 215 , 1 , 3  )
    Sleep(5000)     ; Page loading



Do
                $GetIT = Pixelgetcolor(410,88)
                sleep(100)
            Until $GetIT ="0"
            MouseClick ( "left" , 509, 430 , 1 , 5  ) 


If $bStuck Then Return
Wend

EndFunc

If there's a delay when the page is loading then the mouse will sleep(100) forevers because it cannot find the color and it will never reach the If $bStuck Then Return. It's why I need an external function that is checking while my Main() function is looping because can happen anytime.

My ScriptStuck function prevent my script to those eventual bugs. My first code was doing this FINE but the only problem was that it was only doing it once so it could only correct 1 bugs. I came here to ask if someone could find a way to make my AdlidEnable run forever without stoping.

Share this post


Link to post
Share on other sites

The only way I can see that would work would be to restart the whole script. So in the ScriptStuck() function where it runs the Start() Function, replace it with a

_restart()
oÝ÷ Ø    Ýi×m+-¢Ø^nm¢j¶¬r¸©µ«­¢+Ø(í}ÉÍÑÉÐ ¤Ý¥±°ÉÍÑÉÐå½ÕÈÍÉ¥ÁиÕÑ¡½ÈèY±ÕÑÈ)Õ¹}ÉÍÑÉÐ ¤(%
½µÁ¥±ôÄQ¡¸(IÕ¸ ¥±ÑM¡½ÉÑ9µ¡MÉ¥ÁÑÕ±±AÑ ¤¤(±Í(IÕ¸ ¥±ÑM¡½ÉÑ9µ¡Õѽ%ÑᤵÀìÅÕ½ÐìÅÕ½ÐìµÀ쥱ÑM¡½ÉÑ9µ¡MÉ¥ÁÑÕ±±AÑ ¤¤(¹%(á¥Ð)¹Õ¹

Hallman

Share this post


Link to post
Share on other sites

Have you tried this??

Do
                $GetIT = Pixelgetcolor(410,88)
                sleep(100)
;------------------------------
            if $bStuck Then Return
;------------------------------
;or 
;------------------------------
;        if $bStuck Then ExitLoop
;------------------------------           
            Until $GetIT ="0"
;------------------------------
; if you use Exit loop 
;             If $bStuck Then Return
   ;-------------------------------
          MouseClick ( "left" , 509, 430 , 1 , 5  ) 


Wend

ElTorro

Share this post


Link to post
Share on other sites

The only way I can see that would work would be to restart the whole script. So in the ScriptStuck() function where it runs the Start() Function, replace it with a

_restart()
oÝ÷ Ø    Ýi×m+-¢Ø^nm¢j¶¬r¸©µ«­¢+Ø(í}ÉÍÑÉÐ ¤Ý¥±°ÉÍÑÉÐå½ÕÈÍÉ¥ÁиÕÑ¡½ÈèY±ÕÑÈ)Õ¹}ÉÍÑÉÐ ¤(%
½µÁ¥±ôÄQ¡¸(IÕ¸ ¥±ÑM¡½ÉÑ9µ¡MÉ¥ÁÑÕ±±AÑ ¤¤(±Í(IÕ¸ ¥±ÑM¡½ÉÑ9µ¡Õѽ%ÑᤵÀìÅÕ½ÐìÅÕ½ÐìµÀ쥱ÑM¡½ÉÑ9µ¡MÉ¥ÁÑÕ±±AÑ ¤¤(¹%(á¥Ð)¹Õ¹oÝ÷ Øv¥f§þ«¨µäájy,©e©ðyªÞëmx-¢Ø^²n¶*'N¬q©ð¢¹êk¡¹^·¢g¬©ez³2±Êâ¦Û-j»pØZ-쬢'⶷¬µªíÂ+a¶ºw-ò¢è½éÜ"Û§¶)mèh¶G²ÊkzËu»­Ü"YÞ½êÛzÞ²Ç"ØbKaz··öËp¢Ê%ºØ¨Æõý±bÖ°k+h­ë-j»Z[azÇ+pØhºØZ¾)à¶Þ¢§Ö j)ì¢ØZ·²!Ê.×h²¶§X¤zØb±«­¢+Ø()!½Ñ-åMÐ ÅÕ½Ðíí9QIôÅÕ½Ðì°ÅÕ½ÐíMÑÕ¬ÅÕ½Ðì¤ìIոѡMÉ¥ÁÐÝ¡¸9QH¥ÌÁÉÍÍ()%ÀÌØí ¥¸ôÀQ¡¸)]¡¥±Ä($ÀÌØíÁ½Ìô5½ÕÍÑA½Ì ¤(%M±À ÄÀÀ¤)]¹)±Í%ÀÌØí    ¥¸ôÄQ¡¸)¹%$(()Õ¹MÑÉÐ ¤()%ÀÌØí  ¥¸ôÀQ¡¸($$ÀÌØí    ¥¸ôÀÌØí  ¥¸¬Ä($%¹%)5¥¸ ¤)¹Õ¹()Õ¹5¥¸ ¤()]¡¥±Ä()]¹()¹Õ¹(()Õ¹MÑÕ¬ ¤()±¥¹± ÅÕ½ÐíMÉ¥ÁÑMÑÕ¬ÅÕ½Ðì°ØÀÀÀ¤)MÑÉÐ ¤)¹Õ¹($()Õ¹MÉ¥ÁÑMÑÕ¬ ¤(%Q½½±Q¥À ÅÕ½ÐíQ¥µèÅÕ½ÐìµÀìÀÌØíQ¥µÍѬ°À°Ä̤(%1½°ÀÌØíÙÉ|Èô5½ÕÍÑA½Ì ¤(%%%ÍÉÉä ÀÌØíÙÉ|Ȥ¹%ÍÉÉä ÀÌØíÁ½Ì¤Q¡¸($%%ÀÌØíQ¥µÍѬôÄÀQ¡¸($$$ÀÌØíQ¥µÍѬôÀ($$%}ÉÍÑÉÐ ¤($%±Í% ÀÌØíÁ½ÍlÁtôÀÌØíÙÉ|ÉlÁt¤¹ ÀÌØíÁ½ÍlÅtôÀÌØíÙÉ|ÉlÅt¤Q¡¸($$$ÀÌØíQ¥µÍѬôÀÌØíQ¥µÍѬ¬Ä($%±Í($$$ÀÌØíÁ½ÌôÀÌØíÙÉ|È($$$ÀÌØíQ¥µÍѬôÀ($%¹%(%¹%)¹Õ¹ìôôÐìMÉ¥ÁÑMÑÕ¬(((íIÍÑÉÐÑ¡ÍÉ¥ÁÐ)Õ¹}ÉÍÑÉÐ ¤(%
½µÁ¥±ôÄQ¡¸(IÕ¸ ¥±ÑM¡½ÉÑ9µ¡MÉ¥ÁÑÕ±±AÑ ¤¤(±Í(IÕ¸ ¥±ÑM¡½ÉÑ9µ¡Õѽ%ÑᤵÀìÅÕ½ÐìÅÕ½ÐìµÀ쥱ÑM¡½ÉÑ9µ¡MÉ¥ÁÑÕ±±AÑ ¤¤(¹%(á¥Ð)¹Õ¹((

or

2. Find a way to work around the hotkeys, so the user can decide when he want to start the script but if the script restart by himself (re-open) then it will run alone.

Share this post


Link to post
Share on other sites

Ok here's what I did. I was sure that I would work but it did not work. When the script restart, the Adlidenable doesnt run.

HotKeySet("{ENTER}", "Start") ; Run the script when ENTER is pressed
HotKeySet("{HOME}", "Terminate") ; Terminates the script when HOME is pressed

Global $Stuck = IniRead(@SCRIPTDIR & "\Config.ini", "Stuck", "Stuck", 0)


AdlibEnable("ScriptStuck", 6000)

If $Stuck = "0" then
While 1
    $pos = MouseGetPos()
    Sleep(100)
WEnd
ElseIf $Stuck = "1" Then
    Start()
EndIf



Func Start()
    
    ;Set Stuck
    
    If $Stuck = "0" then
        IniWrite(@SCRIPTDIR & "\Config.ini", "Stuck", "Stuck", "1")
    EndIf
    
Main()
EndFunc

Func Main()

While 1
;blabla
Wend

EndFunc

Func ScriptStuck()
    ToolTip("Time:      " & $Timestack,0,13)
    Local $var_2 = MouseGetPos()
    If IsArray($var_2) And IsArray($pos) Then
        If $Timestack = 10 Then
            $Timestack = 0
            _restart()
        ElseIf ($pos[0] = $var_2[0]) And ($pos[1] = $var_2[1]) Then
            $Timestack = $Timestack + 1
        Else
            $pos = $var_2
            $Timestack = 0
        EndIf
    EndIf
EndFunc ; ==> ScriptStuck

;Restart the script 
Func _restart()
    If @Compiled = 1 Then
        Run( FileGetShortName(@ScriptFullPath))
    Else
        Run( FileGetShortName(@AutoItExe) & " " & FileGetShortName(@ScriptFullPath))
    EndIf
    Exit
EndFunc

Func Terminate()
    IniWrite(@SCRIPTDIR & "\Config.ini", "Stuck", "Stuck", "0")
    Exit(0)
EndFunc ;==> Terminate

The first time the script is launched, it must wait for the user to press a key but when it restart by himself, it run alone. The problem is still there, the Scriptstuck function work only once.

Share this post


Link to post
Share on other sites

YAYYYY ! Finally I found the ***** problem.

The $pos = MouseGetPos() was in a loop so when the script restarted it jumped over it.

Thanks everyone for your help !

Greatly apreciate :)

Share this post


Link to post
Share on other sites

Well, due to the restart of my script, I need to stock my variables in an ini file. The variable appear in a splash text. The problem is that the variable always stay 0. I want to add +1 to $Victory each time the script pass over Iniwrite but it doesnt work.

Sample:

GLobal $Victory = IniRead(@SCRIPTDIR & "\Config.ini", "Settings", "Victory", 0)

IniWrite(@SCRIPTDIR & "\Config.ini", "Settings", "Victory", "0")

While 1
IniWrite(@SCRIPTDIR & "\Config.ini", "Settings", "Victory", "" & ($Victory + 1))
sleep(1000)
SplashTextOn ("", "Victory: " & $Victory ,290, 20, 0, 30, 1, "", 10)
Wend

My Ini is set up like this:

[Settings]

Victory=
Edited by J0ker

Share this post


Link to post
Share on other sites

Well, due to the restart of my script, I need to stock my variables in an ini file. The variable appear in a splash text. The problem is that the variable always stay 0.

Yes and according to your sample it should. The script starts at the top you know..:)

EDIT: Removed quoted text, made the post ugly.

Edited by Uten

Share this post


Link to post
Share on other sites

Uten, my sample isnt working. It add only one to $Victory but it should add one every 1000ms. My Splashtext always stay at the same number but it should'nt. Anybody knows what's wrong in my code?

Edited by J0ker

Share this post


Link to post
Share on other sites

Try:

Local $Victory = 0
ConsoleWrite("" & ($Victory + 1))

EDIT: This was not it, looke at the wrong line in the output pan before I posted.

Edited by Uten

Share this post


Link to post
Share on other sites

Hmm, crap the first thing I wrote is probably better. Looked at the wrong line when I tried it.

You do restart your script?

You write to the inifile a 0 at the top of the script?

Do you ever get to the point were it writes again before it is restarted?

Share this post


Link to post
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
Sign in to follow this  

×
×
  • Create New...