How to Skip Commands if Pixel color code isnt found

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
cleetz
Posts: 25
Joined: 04 Feb 2023, 15:09

How to Skip Commands if Pixel color code isnt found

Post by cleetz » 04 Feb 2023, 15:36

Hello. I am looking for some help with a script Im writing in which AHK ;
Locates a pixel color code
After locating, it jumps to a random location between a set of coordinates among that pixel color patch and clicks

I am wondering, how do I get it to skip a command if the specified color code is not found on the screen, so that it eventually skips enough commands to where it can get get to a part of the script where proper function can resume.
Currently, although the color code I am searching for will not be on the screen, the mouse will move to the area where the color code should be and click on a coordinate everytime anyways.


Code: Select all

PixelSearch, Px, Py, 12, 356, 510, 36, 0x00FF00, 1, Fast
mousemove %px%, %py%
Random, x, 6, 8
Random, y, -4, -6
MouseMove, %x%, %y%, 0, R
sleep 600
click
random,rand, 5500, 7000
sleep rand
Hopefully this format is correct if not I apologize I am new to the forum
THanks for Your time

User avatar
mikeyww
Posts: 26849
Joined: 09 Sep 2014, 18:38

Re: How to Skip Commands if Pixel color code isnt found

Post by mikeyww » 04 Feb 2023, 17:20

Welcome to this AutoHotkey forum!

The documentation is useful.

Example: https://www.autohotkey.com/docs/v1/lib/PixelSearch.htm#ExBasic

If you're new, try the current version of AutoHotkey (v2)!

cleetz
Posts: 25
Joined: 04 Feb 2023, 15:09

Re: How to Skip Commands if Pixel color code isnt found

Post by cleetz » 04 Feb 2023, 20:45

wow the legend replied to me. Im honored. I read that forum post respectively but didnt quite find my answer. Is there any way to potentially steer chunks of commands when coding AHK to where, if the first segment of the command isnt = true, then it skips the rest of that chunk of code and moves to the next segment of the script? I think that even though its not
(A) finding the color code Im searching for,

Code: Select all

PixelSearch, Px, Py, 12, 356, 510, 36, 0x00FF00, 1, Fast
mousemove %px%, %py%
it still precedes to
(B) Move the mouse Randomly between x and y movements

Code: Select all

Random, x, 6, 8
Random, y, -4, -6
MouseMove, %x%, %y%, 0, R
sleep 600
click
random,rand, 5500, 7000
sleep rand
is there a way to make it so if the Color Code I'm searching for isnt on the screen, that it just skips that chunk of code entirely? and goes to the next section where it has a chance to fall on a chunk of code that is appropriate to keep the script functioning, rather than doing a series of executions that hinders the desired outcome?

User avatar
mikeyww
Posts: 26849
Joined: 09 Sep 2014, 18:38

Re: How to Skip Commands if Pixel color code isnt found

Post by mikeyww » 04 Feb 2023, 22:27

You are describing a block.

Code: Select all

PixelSearch.......
If !ErrorLevel {  ; Found
 ; Chunk of code
}
; More chunks

cleetz
Posts: 25
Joined: 04 Feb 2023, 15:09

Re: How to Skip Commands if Pixel color code isnt found

Post by cleetz » 05 Feb 2023, 04:51

:clap: Domo Arigoto Senpai. You may archive this now :bravo:

Post Reply

Return to “Ask for Help (v1)”