Sign in to follow this  
Followers 0
Drew

Pixels - What fun!

4 posts in this topic

Firstly, I'm going to include my script built as is now:

HotKeySet('{esc}', '_Exit')
HotKeySet('`', '_HotKey')

$clicking = False

While 1
   ;Sleep(200); IMPORTANT <- without this line your script would use 100% cpu usage
    
    If $clicking then MouseClick( "left")
wend


Func _HotKey()
    $clicking = Not $clicking
EndFunc


Func _Exit()
    MsgBox( 0, "Thanks!", "This will close the program.")
    Exit    
EndFunc

Works like a charm. But now I'm looking towards upgrading it a bit. Adding a little more automation to the process, and less manual requirements. I'm going to include the code I've come up with, and then explain why I thought it the way I did, and maybe this will help someone show me where I'm wrong.

Here's the code:

HotKeySet('{esc}', '_Exit')
HotKeySet('`', '_HotKey')

$lowlife = PixelSearch( 156, 164, 220, 176, 0xFFFFFF)
$kill = PixelChecksum( 157, 227, 415, 362)
$clicking = False

While 1
   ;Sleep(200); IMPORTANT <- without this line your script would use 100% cpu usage
    If $clicking then MouseClick( "left")
    $monster = MouseGetPos()
wend


Func _HotKey()
    Do
    $clicking = Not $clicking
Until $kill
Mouseclick( "left", 272, 538, 1)
MouseMove( $monster[0], $monster[1])
EndFunc


Func _Exit()
    MsgBox( 0, "Thanks!", "This will close the program.")
    Exit    
EndFunc

Alright. First off, the plan. What's this program meant to do?

HotKeySet('{esc}', '_Exit') ; Exit the program

HotKeySet('`', '_HotKey') ; Perform

$lowlife = PixelSearch( 156, 164, 220, 176, 0xFFFFFF) ; This is meant to check a region to see if the Red ( life ) is gone, leaving white in its place. If white ( 0xFFFFFF ) is there that means the life has fallen below the checked region.

$kill = PixelChecksum( 157, 227, 415, 362) ; When the image ( monster ) dies, it fades; changing the checksum producing a true value ( I think. )

$clicking = False ; Performs the main function, automated clicking.

While 1 ; Main While

;Sleep(200); IMPORTANT <- without this line your script would use 100% cpu usage; I don't use it, but it's included.

If $clicking then MouseClick( "left") ; Continued , The main function of the program.

$monster = MouseGetPos() ; This would ( should ) get the position of the mouse at which point the user strikes the hotkey, and remembers it.

wend ; Ends While

Func _HotKey() ; Declaration

Do ; Where as I do not fully understand "Do's" and "Untils", This area is more likely to generate the error. In my mind, I want this to "Do" the following statements "Until" I get what I want.

$clicking = Not $clicking ; This is what it should continue doing "Until"

Until $kill ; "Until" this happens. ( PixelCheckSum comes back true ( until something changes ))

Mouseclick( "left", 272, 538, 1) ; When something changes, Click this point.

MouseMove( $monster[0], $monster[1]) ; And than move back to the starting location and wait for the user to strike the hotkey.

EndFunc ; End Function

Func _Exit() ; Performed when the user strikes the {esc} key, the Exit hotkey.

MsgBox( 0, "Thanks!", "This will close the program.") ; Commands performed on occasion.

Exit ; Ultimate result.

EndFunc ; End function.

=============================================================

I apologize for what may turn out to be a messy post ( looks neat now, format may change when posted ), but my goal is to explain in depth what I'm trying to do to get the best responses. So now, I'll explain what I'm trying to do in English.

When "`" is struck, I want the program to continue clicking the current position until the area designated changes. When this happens, the mouse needs to move down and click a position, before moving back up to the starting location before the user struck the hotkey. This needs to be in a loop, whereas the user may strike the "`" key and receive the same results time and time after.

Ideas on how to go about this, examples, and criticism are all welcome. I'm a messy writer, I know.

Thanks again, as this wouldn't be the first time you guys have helped me.

*Drew

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Nothing updates $kill while the Do/Until loop is running. Whatever value it started with will be unchanged and the loop will not exit.

:)

P.S. Also, PixelChecksum returns a checksum integer value, so it will always return a non-zero, so that will always be interpreted as TRUE if used for a boolean, like with Until.

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

The $kill I thought would be updated by itself. Or what I mean is, The area the checksum watches will contain an image. after enough clicking takes place, the image fades ( dies ) producing a visual change. When that happens it needs to click a new button and move back to the starting position, exiting the loop to wait for command from the user.

But did I do the Do and Until correctly? I've had trouble understanding it and its uses.

How would I ask the program if the checksum was returned true? ( something changed ), so that it knows when to go and click the button and finish?

Share this post


Link to post
Share on other sites

The $kill I thought would be updated by itself. Or what I mean is, The area the checksum watches will contain an image. after enough clicking takes place, the image fades ( dies ) producing a visual change. When that happens it needs to click a new button and move back to the starting position, exiting the loop to wait for command from the user.

But did I do the Do and Until correctly? I've had trouble understanding it and its uses.

How would I ask the program if the checksum was returned true? ( something changed ), so that it knows when to go and click the button and finish?

Save the checksum value to a variable, then come back later (perhaps in a loop) and get it again, comparing the new value to the previous one to see if it changed.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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