Sign in to follow this  
Followers 0
inmysights

Debug while running

6 posts in this topic

I have a very simple script, 6 mouseclicks, MouseClick($MOUSE_CLICK_LEFT, 955,250, 1,0) and I have AutoItConstants.au3 included, with all button includes as well. Simple and easy.

As soon as I add these into a function:

func Planet1()
MouseClick($MOUSE_CLICK_LEFT, 955,250, 1,0)
Sleep(3000)
MouseClick($MOUSE_CLICK_LEFT, 1237,711, 1,0)
Sleep(3000)
MouseClick($MOUSE_CLICK_LEFT, 1680, 873, 1,0)
Sleep(3000)
MouseClick($MOUSE_CLICK_Right)
MouseClick($MOUSE_CLICK_Right)
MouseClick($MOUSE_CLICK_Right)
MouseClick($MOUSE_CLICK_Right)
Sleep(2000)
EndFunc

and I use this with a button:

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
            Case $Planet1
            Planet1()
            
    EndSwitch
WEnd

 

it fails, but I have no errors in the console, can I debug somehow while hitting the button and watch a debug window?

Thank you, I am learning as I go! 

 

 

Share this post


Link to post
Share on other sites



Do you mean you're not getting any error messages in the Scite output?

 

$MOUSE_CLICK_LEFT and $MOUSE_CLICK_Right are not declared, would be the error messages you should get. Replace them with "Left" and "Right" (respectively) and it will work

MouseClick("Left", 955, 250, 1,0)
Sleep(3000)
MouseClick("Left", 1237,711, 1,0)
Sleep(3000)
MouseClick("Left", 1680, 873, 1,0)
Sleep(3000)
MouseClick("Right")
MouseClick("Right")
MouseClick("Right")
MouseClick("Right")
Sleep(2000)

 

Share this post


Link to post
Share on other sites

Thank you for the reply, yes, the console at the bottom, I get no errors.

Thank you for the clearer mousclick, I did not notice you can do it like that.

it does not work every time though, maybe after I hit f5 3-5 times , I would like to know why it does not work every single time.

is there a way to debug it?

 

Thank you

Share this post


Link to post
Share on other sites

It's most likely caused by the very long Sleeps you use.

 

Something you could do is to wrap your mouseclicks controled by an if statement that checks a variable

#include <AutoItConstants.au3>

Global $clicking = False

HotKeySet("{F5}", "_Click")

While (True)
    Sleep(100)
WEnd


Func _Click()
    $clicking = Not $clicking
    If ($clicking) Then
        MouseClick("Left", 955, 250, 1,0)
        If (_InternalSleep(3000)) Then Return
        MouseClick("Left", 1237,711, 1,0)
        If (_InternalSleep(3000)) Then Return
        MouseClick("Left", 1680, 873, 1,0)
        If (_InternalSleep(3000)) Then Return
        MouseClick("Right")
        MouseClick("Right")
        MouseClick("Right")
        MouseClick("Right")
        If (_InternalSleep(2000)) Then Return
        ; Reset the control variable
        $clicking = False
    EndIf
EndFunc

Func _InternalSleep(Const ByRef $sleep_time)
    Local $internal_timer = TimerInit()

    While ($clicking and (TimerDiff($internal_timer) < $sleep_time))
        ToolTip("_InternalSleep called | Sleep time = " & $sleep_time & " | Time Slept = " & Round(TimerDiff($internal_timer) / 1000, 2) & 's')
        Sleep(10)
    WEnd

    ToolTip("")

    If (Not $clicking) Then
        Return -1
    Else
        Return 0
    EndIf
EndFunc

A lot of people will do something like this for a while loop that can pause/unpause a script, just replaced If ($clicking) Then ... Endif with While ($clicking) ... Wend. It will execute the MouseClicks until you press the Hotkey again

Share this post


Link to post
Share on other sites

It's most likely caused by the very long Sleeps you use.

 

Something you could do is to wrap your mouseclicks controled by an if statement that checks a variable

#include <AutoItConstants.au3>

Global $clicking = False

HotKeySet("{F5}", "_Click")

While (True)
    Sleep(100)
WEnd


Func _Click()
    $clicking = Not $clicking
    If ($clicking) Then
        MouseClick("Left", 955, 250, 1,0)
        If (_InternalSleep(3000)) Then Return
        MouseClick("Left", 1237,711, 1,0)
        If (_InternalSleep(3000)) Then Return
        MouseClick("Left", 1680, 873, 1,0)
        If (_InternalSleep(3000)) Then Return
        MouseClick("Right")
        MouseClick("Right")
        MouseClick("Right")
        MouseClick("Right")
        If (_InternalSleep(2000)) Then Return
        ; Reset the control variable
        $clicking = False
    EndIf
EndFunc

Func _InternalSleep(Const ByRef $sleep_time)
    Local $internal_timer = TimerInit()

    While ($clicking and (TimerDiff($internal_timer) < $sleep_time))
        ToolTip("_InternalSleep called | Sleep time = " & $sleep_time & " | Time Slept = " & Round(TimerDiff($internal_timer) / 1000, 2) & 's')
        Sleep(10)
    WEnd

    ToolTip("")

    If (Not $clicking) Then
        Return -1
    Else
        Return 0
    EndIf
EndFunc

A lot of people will do something like this for a while loop that can pause/unpause a script, just replaced If ($clicking) Then ... Endif with While ($clicking) ... Wend. It will execute the MouseClicks until you press the Hotkey again

This is great, works every time when I just run it, so how do I add this to a button and still execute it every time?

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

This is great, works every time when I just run it, so how do I add this to a button and still execute it every time?

Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Planet1
            _Click()
    EndSwitch

 

Edited by InunoTaishou

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