Jump to content

Final Tweak I need that isnt having troubles.


Recommended Posts

My problem is that when the loop is initiated everything is fine until I go to hit the "Stop!" button, it seems my program freezes in a sense since nothing happens. What's supposed to happen is that the button obviously exits the loop of clicking and sets the data for the "start" button to "start" again (from "stop")

Take a look at the Function I have towards the very end, it's under Func _start()

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.0.0
 Author:Dazzled

 Script Function: Allows for Adamantite all night to be farmed up!
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

#Include <Misc.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ImageListConstants.au3>
#Include <GuiMenu.au3>
#include <GuiComboBoxEx.au3>
#include <GUIButton.au3>
#Include <GuiSlider.au3>
#include <IE.au3>
#include <SliderConstants.au3>
#include <StructureConstants.au3>

FileInstall("C:\Users\Kevin\Desktop\Stinky Pete\Images\Icon.ico", @Scriptdir & "\Images\Icon.ico")
FileInstall("C:\Users\Kevin\Desktop\Stinky Pete\Images\Info.ico", @Scriptdir & "\Images\Info.ico")
FileInstall("C:\Users\Kevin\Desktop\Stinky Pete\Images\Coord.ico", @Scriptdir & "\Images\Coord.ico")
FileInstall("C:\Users\Kevin\Desktop\Stinky Pete\Images\StinkyPeteBG.jpg", @Scriptdir & "\Images\StinkyPeteBG.jpg")


HotKeySet( "{PAUSE}", "TogglePause")
Global $Paused, $Mouse_Pos

#Region ### START Koda GUI section ### Form=
$main = GUICreate("Stinky Pete", 301, 201, -1, -1)
GUISetIcon(@Scriptdir & "\Images\Icon.ico")
$Website = GUICtrlCreateButton("Info", 232, 120, 61, 75, BitOR($BS_ICON,$WS_GROUP))
GUICtrlSetImage(-1, @Scriptdir & "\Images\Info.ico", -1)
GUICtrlSetCursor (-1, 0)
Global $slider1 = GUICtrlCreateSlider(10, 175, 100, 20)
GUICtrlSetBkColor(-1,0)
GUICtrlSetLimit(-1, 255, 126)
GUICtrlSetData(-1, 255)
GUISetState()
$Xinput = GUICtrlCreateInput("0", 8, 74, 57, 21)
$Yinput = GUICtrlCreateInput("0", 8, 98, 57, 21)
$coords = GUICtrlCreateButton("", 8, 130, 57, 41, BitOR($BS_ICON,$WS_GROUP))
GUICtrlSetImage(-1, @Scriptdir & "\Images\Coord.ico", -1)
GUICtrlSetCursor (-1, 0)
$start = GUICtrlCreateButton("Start!", 112, 160, 110, 33, $WS_GROUP)
GUICtrlSetCursor (-1, 0)
$background = GUICtrlCreatePic(@Scriptdir & "\Images\StinkyPeteBG.jpg", 0, 0, 300, 200)
GUISetState(@SW_SHOW, $main)
#EndRegion ### END Koda GUI section ###

WinSetOnTop("[CLASS:AutoIt v3 GUI]", "", 1)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $nMsg = $slider1
            WinSetTrans($main, "", GUICtrlRead($slider1))
            ToolTip("")
            sleep (100)
        Case $Website
            ToolTip("")
            ShellExecute("http://www.Google.com")
        Case $coords
            ToolTip('Please click anywhere on the screen to set your coordinates', 0, 0)
            Sleep(100)
            _get_mousepos()
        Case $start
            GUICtrlSetData($start, "Stop!")
            TooLTip('', 0, 0)
            _start()
    EndSwitch
WEnd

Opt("TrayIconHide", 1)

Func _get_mousepos()
    Local $dll
    While Not _IsPressed("01")
        Sleep(10)
    WEnd
    DllClose($dll)
    Local $Mouse_Pos = MouseGetPos()
    GUICtrlSetData($Xinput, $Mouse_Pos[0])
    GUICtrlSetData($Yinput, $Mouse_Pos[1])
EndFunc

Func TogglePause()
    If GUICtrlRead($start) = "Start!" Then Return
    $Paused = Not $Paused
    While $Paused
        Sleep(100)
        ToolTip('"', 0, 0)
    WEnd
    ToolTip("")
EndFunc

Func _start()
    Local $X, $Y, $Xcoord, $Ycoord
    $X = GUICtrlRead($Xinput)
    $Y = GUICtrlRead($Yinput)
    While 1
    MouseClick("right", $X, $Y, 1)
    Sleep(3250)
    MouseClick("left", $X, $Y, 1)
    SLeep(200)
    MouseClick("left", $X, $Y+20, 1)
    SLeep(200)
    MouseClick("left", $X, $Y+40, 1)
    SLeep(200)
    MouseClick("left", $X, $Y+60, 1)
    Sleep(1000)
                Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
        Exit
    Case $start
        GUICtrlSetData($start, "Start!")
        ExitLoop 1
EndSwitch
WEnd
EndFunc

P.S. On my computer the setting data of the "start" button is a little slow, there is a small time of there being no button before the new one loads, can this be smoothed out?

Link to comment
Share on other sites

  • Moderators

kjpolker,

I would imagine that the reason your script appears to "freeze" is that you have very little time during the While...WEnd loop in function _start to react to a click on the "Stop" button because you spend the majority of the time in Sleep statements when the GUI is unresponsive. What I suggest is to modify the function so that it looks for button presses during the Sleeps and not just once every 5 secs or so. :P

Perhaps change the function _start and add another function something like this:

Func _start()
    Local $X, $Y, $Xcoord, $Ycoord
    $X = GUICtrlRead($Xinput)
    $Y = GUICtrlRead($Yinput)
    While 1
        ;ConsoleWrite("Clicking stuff" & @CRLF)
        ;MouseClick("right", $X, $Y, 1)
        If _Waiter(3250) = 1 Then Return
        ;MouseClick("left", $X, $Y, 1)
        If _Waiter(200) = 1 Then Return
        ;MouseClick("left", $X, $Y + 20, 1)
        If _Waiter(200) = 1 Then Return
        ;MouseClick("left", $X, $Y + 40, 1)
        If _Waiter(200) = 1 Then Return
        ;MouseClick("left", $X, $Y + 60, 1)
        If _Waiter(1000) = 1 Then Return

    WEnd
EndFunc   ;==>_start

Func _Waiter($iTime)

    $iBegin = TimerInit()
    Do
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Exit
            Case $start
                GUICtrlSetData($start, "Start!")
                Return 1
        EndSwitch

    Until TimerDiff($iBegin) > $iTime

    Return 0

EndFunc

Now you look for the button press for most of the loop and as a result you should see a much more responsive script. :party:

I hope this helps. :mellow:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

That does make way more sense but I am a little confused on what you wrote, I am to have another function to be going on during start your saying? one is the loop and one looks for my clicks? or is the example you gave me exactly what I need? It looks like you canceled all my Clicks out with ";".

Link to comment
Share on other sites

  • Moderators

kjpolker,

It looks like you canceled all my Clicks out with ";"

Commenting out the clicks was for my testing - just uncomment them in your script. :mellow:

M23

Edit: Except the ConsoleWrite line which you can delete, of course!

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I think you don't like my version -> http://www.autoitscript.com/forum/index.php?showtopic=116311&view=findpost&p=811747.

BR,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

  • Moderators

UEZ,

My apologies - I did not realise you had replied earlier.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

UEZ,

My apologies - I did not realise you had replied earlier.

M23

No, my comment was to kjpolker not to you!!! I tried to help him in the thread I mentioned... Your solution is more elegant than mine!

BR,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

  • Moderators

UEZ,

OK. :P

Congratulations, by the way - and good luck in the quarter-finals. :mellow:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

UEZ,

OK. :P

Congratulations, by the way - and good luck in the quarter-finals. :mellow:

M23

Thanks, that will be a very hard game for us! May the best man win...

BR,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Good luck to you guys! and thank you both for everything, I did do my homework UEZ and got it all the way I wanted it except for that little problem which is posted here.

P.S. What would I need to put in the waiter function? my clicking? I assume it is saying, if _waiter is looping is true than continue? Is this just making it sleep without making the program unresponsive?

Edited by kjpolker
Link to comment
Share on other sites

  • Moderators

kjpolker,

What would I need to put in the waiter function?

Nothing - it is just there to make the GUI controls active during the waiting periods between MouseClicks. As I explained much earlier in the thread, the reason your script appears to freeze was that you had almost no time to look for the GUI control activation - using this function looks for this activation for nearly all of the time. :P

I assume it is saying, if _waiter is looping is true than continue?

Exactly the opposite! :party: If you press the [X] during the _waiter function, you exit immediately. If you press the "Start/Stop" buttun, the function returns 1, if it runs until the timer tells it to stop, it returns 0. This return value is tested in the _start function and if 1 is returned (i.e. the button was pressed), the _start function ends at that point.

Here is the code as I should have posted it above (I was still suffering from the abject display of that over-paid and under-achieving England team yesterday):

Func _start()
    Local $X, $Y, $Xcoord, $Ycoord
    $X = GUICtrlRead($Xinput)
    $Y = GUICtrlRead($Yinput)
    While 1
        MouseClick("right", $X, $Y, 1)
        If _Waiter(3250) = 1 Then Return
        MouseClick("left", $X, $Y, 1)
        If _Waiter(200) = 1 Then Return
        MouseClick("left", $X, $Y + 20, 1)
        If _Waiter(200) = 1 Then Return
        MouseClick("left", $X, $Y + 40, 1)
        If _Waiter(200) = 1 Then Return
        MouseClick("left", $X, $Y + 60, 1)
        If _Waiter(1000) = 1 Then Return

    WEnd
EndFunc   ;==>_start

Func _Waiter($iTime)

    $iBegin = TimerInit()
    Do
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Exit
            Case $start
                GUICtrlSetData($start, "Start!")
                Return 1
        EndSwitch

    Until TimerDiff($iBegin) > $iTime

    Return 0

EndFunc

All clear now? :mellow:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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