Jump to content

Stop code from running automaticly?


Brigzzy
 Share

Recommended Posts

Hello, I'm having some trouble with a script I've been working on, and I'm hoping someone here can help. I apologize if this is something really remedial, but I'm pretty new at this. I'm trying to write a script to automate some of the more tedious parts of a game that I play (clicking and key presses mostly), and I got my first script working nicely. My next revision (the one I'm having a problem with) has a GUI implemented, but I'm running into a problem. Instead of asking me how many times it should run, and doing so (like my last script did) the GUI pops up, it doesn't ask for any input but begins clicking and key pressing presumably forever. I'm hoping someone here can help me figure out where I went wrong. Code is below

HotKeySet("x", "MyExit")
Local $c

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=E:\mydocs\Downloads\koda\Forms\Form1.kxf
$Form1 = GUICreate("Form1", 222, 203, 316, 112)
$Label1 = GUICtrlCreateLabel("Clean Dirty Stones", 56, 64, 99, 17)
$Input2 = GUICtrlCreateInput("Input2", 56, 88, 97, 21)
$Button2 = GUICtrlCreateButton("Clean", 80, 128, 57, 25, $WS_GROUP)
$Group1 = GUICtrlCreateGroup("Auto Cleaner", 40, 32, 145, 129)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState()
#EndRegion ### END Koda GUI section ###

Local $Button2, $Input2

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $nMsg = $WS_GROUP
            Do
            MouseMove(728, 537)
               send("{F4}")
               sleep(1000)
               MouseClick("Left")
               sleep(1000)
               $c +=1
            Until $c=$Input2

    EndSwitch
WEnd
 Func MyExit()
     Exit 
 EndFunc
Link to comment
Share on other sites

Case $nMsg = $Button2
            Do
            MouseMove(728, 537)
               send("{F4}")
               sleep(1000)
               MouseClick("Left")
               sleep(1000)
               $c +=1
            Until $c=GUICtrlRead($Input2)

Case $nMsg = $Button2

and

$c=GUICtrlRead($Input2)

is all you need.

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

Thank you for your help, but that didn't seem t do the trick. It still moves the mouse and starts clicking away. Here is another copy of what my script looks like now.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=E:\mydocs\Downloads\koda\Forms\Form1.kxf
$Form1 = GUICreate("Form1", 222, 203, 316, 112)
$Label1 = GUICtrlCreateLabel("Clean Dirty Stones", 56, 64, 99, 17)
$Input2 = GUICtrlCreateInput("Input2", 56, 88, 97, 21)
$Button2 = GUICtrlCreateButton("Clean", 80, 128, 57, 25, $WS_GROUP)
$Group1 = GUICtrlCreateGroup("Auto Cleaner", 40, 32, 145, 129)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState()
#EndRegion ### END Koda GUI section ###

Local $Button2, $Input2
HotKeySet("x", "MyExit")
Local $c

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $nMsg = $Button2             
            Do             
                MouseMove(728, 537)                
                send("{F4}")                
                sleep(1000)                
                MouseClick("Left")                
                sleep(1000)                
                $c +=1             
            Until $c=GUICtrlRead($Input2)
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
 Func MyExit()
     Exit 
 EndFunc

I don't really know anything about coding (what I have here, I just pieced together from the help file, and from enaiman), but could it be executing because of the "Do" and "Until" lines? If the script is just running from to to bottom, and there isn't anything there to tell it not to run, maybe that's why it's looping like this? Any help would be appreciated :)

Link to comment
Share on other sites

Never mind, I seem to have fixed it, but I'm not sure why. In the interest of learning, could someone please explain why this worked? On a whim, I replaced:

Switch $nMsg

With:

Switch $Input2

Now when I type a value into the input box, the mouse moves and clicks that many times. Fantastic :)

Link to comment
Share on other sites

When you use "Local" on a value that already exist it get's recreated as an empty value which happen to be true when you do "$nMsg = $Button2".

So you need to remove "Local $Button2, $Input2" or move it to BEFORE you save the ControlID in it.

Also that thing you do with the $c seems very out of place (and it doesn't work at all like you have it now).

Try something like this:

For $X = 0 To GUICtrlRead($Input2)            
                MouseMove(728, 537)                
                send("{F4}")                
                sleep(1000)                
                MouseClick("Left")                
                sleep(1000)
            Next

(no $c needed anymore)

Edited by AdmiralAlkex
Link to comment
Share on other sites

When you use "Local" on a value that already exist it get's recreated as an empty value which happen to be true when you do "$nMsg = $Button2".

So you need to remove "Local $Button2, $Input2" or move it to BEFORE you save the ControlID in it.

Also that thing you do with the $c seems very out of place (and it doesn't work at all like you have it now).

Try something like this:

For $X = 0 To GUICtrlRead($Input2)            
                MouseMove(728, 537)                
                send("{F4}")                
                sleep(1000)                
                MouseClick("Left")                
                sleep(1000)
            Next

(no $c needed anymore)

Aah, thank you good sir :) Although it was running one more time than the value I gave it, but changing the $X = 0 to a 1 fixed that right up.
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...