Sign in to follow this  
Followers 0
J0ker

AdlibEnable Error

37 posts in this topic

#1 ·  Posted (edited)

Ok, I'm having problem with a certain part of my script. It has been made to protect the script to stuck, it's an anti-stuck function. A function is called every 6000ms to check if the mouse isnt moving. If the test succeed 10 time in a row, that mean that the script is stuck, then the script restart. I'm having one problem:

1. If the test suceed and the function Start() is called, the AdlibEnable stop to work and I dont know why.

;Variables
Global $Paused, $pos, $Timestack

; If the Mouse is stuck, Restart the script 

AdlibEnable("ScriptStuck", 6000)

While 1
    $pos = MouseGetPos()
    Sleep(500)
WEnd


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
            Start()
        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 ; 



Func Start()

;blabla
Main()
EndFunc

Func Main()
While 1
sleep(100)
While
;blabla

EndFunc
oÝ÷ Økçm¢Zqëaxe±'i¹^ªê-IÊâ¦Ô­¹É*ºzÓM"ÈzØ^1¨§¶§¶µªí~éܶ*'[¢Ø]¡ë'·
+eiÇjëh×6 ToolTip("Time:      " & $Timestack,0,13)
in the function to see if the function was working or not. It's how I know that it work well but when the func start() is called, Func ScriptStuck doesnt work anymore. Edited by J0ker

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You've got 2 whiles

While 1
    $pos = MouseGetPos()
    Sleep(500)
WEnd
; Wait until ENTER is pressed to start the script
While 1          ; This should be before the AntiStuck script but If I place it before, it doesnt work
    sleep(100)
Wend

Just noticed it :) Would it make a difference??

Edited by bert

Share this post


Link to post
Share on other sites

Works for me:

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

;Variables
Global $Paused, $pos, $Timestack

; If the Mouse is stuck, Restart the script 

AdlibEnable("ScriptStuck", 6000)

While 1
    $pos = MouseGetPos()
    Sleep(500)
WEnd


Func Start()


EndFunc

Func Main()

;

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
            Start()
        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 ;

Share this post


Link to post
Share on other sites

@Bert : your script doesnt work for me.

I tried this and it's not working

AdlibEnable("ScriptStuck", 6000)

While 1
    $pos = MouseGetPos()
    Sleep(100)
WEnd

Func ScriptStuck()
    ToolTip("Time:      " & $Timestack,0,13)
    Local $var_2 = MouseGetPos()
    If IsArray($var_2) And IsArray($pos) Then
        If $Timestack = 5 Then
            $Timestack = 0
             AdlibDisable()
            AdlibEnable("ScriptStuck", 6000)
            Start()
        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 ;

Why when the function call Start(), the AdlidEnabe stop to work?

Share this post


Link to post
Share on other sites

So you want Start () to be run if the test to see if the mouse has not moved in (whatever the time was...) and if enter was pressed you want Start () to be called? Is that right?? cause now im confusing myself :)

Share this post


Link to post
Share on other sites

The Enter key doesnt change anything, I just wanted to know why when a function is called from inside an AdlildEnable, the AdlidEnable stop to work? How can I correct this?

Share this post


Link to post
Share on other sites

The Enter key doesnt change anything, I just wanted to know why when a function is called from inside an AdlildEnable, the AdlidEnable stop to work? How can I correct this?

:) I dont know......

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

The Enter key doesnt change anything, I just wanted to know why when a function is called from inside an AdlildEnable, the AdlidEnable stop to work? How can I correct this?

Does anyone know why?

Edited by J0ker

Share this post


Link to post
Share on other sites

this works for me

;Variables
Global $Paused, $pos, $Timestack

; If the Mouse is stuck, Restart the script

AdlibEnable("ScriptStuck", 6000)

While 1
    $pos = MouseGetPos()
    Sleep(500)
WEnd


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
            Start()
        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 ;



Func Start()

ToolTip("Time:      " & $Timestack,0,13, "Start")
EndFunc

Func Main()

ToolTip("Time:      " & $Timestack,0,13, "Main")

EndFunc

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Valuater : I just putted ToolTip("Time: " & $Timestack,0,13) to see if the the Function ScriptStuck() was working, it's not part of my script. Maybe I explained wrong my problem:

I have a long script. I made the Adlilenable to prevent the script to eventual bugs. It runs as an external function while my main script is looping. If there's a delay and the script stuck, the function ScriptStuck will act as an AntiStuck. The problem in my script is that the AdlidEnable work fine until the script is stuck for the first time and $TimeStack = 10 so the function Start() is called.In short, it work only one time then then AdlidEnable stop to work. I want to find a way to correct that. Why the AdildEnable work only one time?

EDIT: If I run this little script alone, it work but If I run it in my real script ( there's a loop in the Main function) it work only one time.

Edited by J0ker

Share this post


Link to post
Share on other sites

Valuater : I just putted ToolTip("Time: " & $Timestack,0,13) to see if the the Function ScriptStuck() was working, it's not part of my script. Maybe I explained wrong my problem:

I have a long script. I made the Adlilenable to prevent the script to eventual bugs. It runs as an external function while my main script is looping. If there's a delay and the script stuck, the function ScriptStuck will act as an AntiStuck. The problem in my script is that the AdlidEnable work fine until the script is stuck for the first time and $TimeStack = 10 so the function Start() is called.In short, it work only one time then then AdlidEnable stop to work. I want to find a way to correct that. Why the AdildEnable work only one time?

EDIT: If I run this little script alone, it work but If I run it in my real script ( there's a loop in the Main function) it work only one time.

I am telling you that this test script you posted (with the 1 tooltip addition i made) is still running on my computer and still working... there is no problem with this script continueing the AdlibEnable() Function

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

I forgot to add something to the script I posted here.

;Variables
Global $Paused, $pos, $Timestack

; If the Mouse is stuck, Restart the script

AdlibEnable("ScriptStuck", 6000)

While 1
    $pos = MouseGetPos()
    Sleep(500)
WEnd


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
            Start()
        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 ;



Func Start()

Main()
EndFunc

Func Main()



EndFunc

The function start() call the function Main().

Edited by J0ker

Share this post


Link to post
Share on other sites

works....

;Variables
Global $Paused, $pos, $Timestack, $xtimes

; If the Mouse is stuck, Restart the script

AdlibEnable("ScriptStuck", 6000)

While 1
    $pos = MouseGetPos()
    Sleep(500)
WEnd


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
            Start()
        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



Func Start()

    Main()
EndFunc   ;==>Start

Func Main()
    $xtimes += 1
    MsgBox(0x0, "test", $xtimes, 2)

EndFunc   ;==>Main

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Yay, I found out where my problem came from. I'm sure that it's because of the while 1. I need to correct the problem now that I know that it came from there.

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

;Variables
Global $Paused, $pos, $Timestack

; If the Mouse is stuck, Restart the script

AdlibEnable("ScriptStuck", 6000)

While 1
    $pos = MouseGetPos()
    Sleep(500)
WEnd


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
            Start()
        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



Func Start()

MouseClick ( "left" , 525, 270 , 1 , 3  )

sleep(500)

    Main()
EndFunc   ;==>Start

Func Main()

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


    While 1                                                 ; Problem came from here
        sleep(100)
        Wend

EndFunc   ;==>Main

I added a loop to this script and the Adlidenable work only one time like in my real script.

Edited by J0ker

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

The problem is ... I think adlib wont run again until that last function it called is done running.

It's set up like this:

AdlibEnable() calls ...

---------------------------ScriptStuck(), it called ...

---------------------------------------------------------Start() which called ...

---------------------------------------------------------------------------------------Main()

So ... Adlib wont call ScriptStuck again until the func Main() is done, which alows Start() to finish, which allows ScriptStuck() to finish, which at the end lets Adlib finish.

So instead of using AdlibEnable, have the check in your Main() func loop with TimerInit() and TimerDiff()

Edited by Hallman

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

I understand what your saying Hallman but why did it work the first time and not the other time?

The Scriptstuck function need to be external because this function protect my script to stuck. I cant implant it at a certain point in my loop.

Edited by J0ker

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

Here I fixed it for you :) It worked in the first example, because the was no loop to keep the fucntion running. So, Adlibs function ended.

HotKeySet("{ENTER}", "HotkeyStart") ; Run the script when ENTER is pressed

Global $Script_Start = 0

;Variables
Global $Paused, $pos, $Timestack

; If the Mouse is stuck, Restart the script

While 1
    If $Script_Start = 1 Then Start()
WEnd

Func HotkeyStart()
    
    If $Script_Start = 0 Then
        $Script_Start = 1
    Else
        $Script_Start = 0
    EndIf
    
EndFunc   ;==>HotkeyStart


Func Start()
    TrayTip("Test", "Script Started ...", 3)

    MouseClick("left", 525, 270, 1, 3)

    Sleep(500)

    Main()

EndFunc   ;==>Start

Func Main()

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

    $MainTimer = TimerInit() ; timer which waits for the 600 m/s mark.
    
    $Base_Mouse_Coordinates = MouseGetPos() ; get the origional coordinates
    
    While 1 ; Problem came from here
        $Current_Mouse = MouseGetPos() ; get new coordinates
        
        If $Base_Mouse_Coordinates[0] <> $Current_Mouse[0] And $Base_Mouse_Coordinates[1] <> $Current_Mouse[1] Then ; If mouse has moved, reset check
            $MainTimer = TimerInit()
            $Base_Mouse_Coordinates = MouseGetPos()
        EndIf
        
        If TimerDiff($MainTimer) > 6000 Then Return 0 ; If the mouse wasn't moved for 6 secs, end func
        
        Sleep(100)
    WEnd

EndFunc   ;==>Main

Hallman

EDIT: Code error. It's correct now

Edited by Hallman

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

Ok I will test this, but does this will do the same thing that Adlid was doing? because if not, it wont work for my script.

It need to be external as I said cause the script can stuck anytime in my loop ( my loop is over 350 lines of code)

Edited by J0ker

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

Well this is gonna be difficult. Hopfully you can come up with something based on my example. If it comes down to it, you can always have the script restart itself to solve the adlib problem. Well I gotta get off the internet. Dial up takes up phone line and my mom hates it :)

Edited by Hallman

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

Thanks for your help hallman but your code wont work with my script.

I need to find a way to work around my problem using my basic code.

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

;Variables
Global $Paused, $pos, $Timestack

; If the Mouse is stuck, Restart the script

AdlibEnable("ScriptStuck", 6000)

While 1
    $pos = MouseGetPos()
    Sleep(500)
WEnd


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
            Start()
        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



Func Start()

MouseClick ( "left" , 525, 270 , 1 , 3  )

sleep(500)

    Main()
EndFunc   ;==>Start

Func Main()

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


    While 1                                                 ;  ######### Problem come from here ##########
        sleep(100)
        Wend

EndFunc   ;==>Main
Edited by J0ker

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  
Followers 0