script pixel and image check

Ask gaming related questions (AHK v1.1 and older)
Green Astronaut
Posts: 84
Joined: 13 Dec 2020, 08:35

script pixel and image check

19 Feb 2021, 15:39

hello guys, i have a big problem to create a script and would like some help, it is a script that works with pixelsearch and also imagesearch

let's go to the explanation:
first he checks the coordinates

X = 680
Y = 25
until
X = 1000
Y = 40

in search of color
0x8F00B7 = PURPLE COLOR

if that color is found no action is taken,
more if the color is not found, it looks for an image in the coordinates

X = 530
Y = 578
until
X = 580
Y = 600

and if found, press the "END" key
Last edited by BoBo on 19 Feb 2021, 16:18, edited 1 time in total.
Reason: Moved to Gaming section.
User avatar
mikeyww
Posts: 26889
Joined: 09 Sep 2014, 18:38

Re: script pixel and image check

19 Feb 2021, 17:07

Code: Select all

PixelSearch,,, 680, 25, 1000, 40, 0xB7008F,, Fast ; Blue, green, red
If !ErrorLevel
 Return
ImageSearch,,, 530, 578, 580, 600, [image]        ; Provide path to image
Send % ErrorLevel ? "" : "{End}"
Green Astronaut
Posts: 84
Joined: 13 Dec 2020, 08:35

Re: script pixel and image check

19 Feb 2021, 21:25

I tested more it didn't work
I will put a picture of the game and do a more detailed explanation

[image] https://imgur.com/a/fCDRF8d

first the script tests whether the purple color bar at the top of the photo is found,
(which is marked in red) and if found, no action should be taken,

but the purple bar has a link to the image (which is marked in red) at the bottom of the photo

the image at the bottom represents a waiting time to be able to use the purple bar again,

now i will explain how i would like the script to work again:

first it is checked if the purple color is found in that position. X = 680 Y = 25 until X = 1000 Y = 40

if it is found no action is taken.
if not found
there it is checked if the image is active, (when the image is active the same in the photo is because I can't activate the purple bar again)
coordenate image : X = 530 Y = 578 until X = 580 Y = 600

however if the image is active, I would like to press the "END" key that makes the image disappear immediately, thus making it possible to activate the purple bar.

(I will activate the purple bar manually)


I would like this check to happen every 1 second,

the image path is this:
C:\Users\ Alex\ Desktop\images


image link: https: //imgur.com/a/8lycUlz
User avatar
mikeyww
Posts: 26889
Joined: 09 Sep 2014, 18:38

Re: script pixel and image check

19 Feb 2021, 21:45

Feel free to post your revised script. You will need to add your image path. When I checked the bar, I found the following four BGR colors, but not the one that you mentioned.

0xA50082
0xB50190
0xA90D89
0x63074E

How did you determine the color?

You can decide what color you want to target.

You can debug the script by adding lines to determine what is happening at each step. Add a MouseMove to a corner of your search area. Is each search failing, or succeeding? You can add lines to display the ErrorLevels. How did you determine your coordinates?
Green Astronaut
Posts: 84
Joined: 13 Dec 2020, 08:35

Re: script pixel and image check

20 Feb 2021, 01:43

I determined both the color and the coordinates using the window spy tool
is that standard that comes directly with AHK

I'm new to programming and I'm still studying, so any help would be appreciated.
I have a little sense of script reading, but I don't know much about creating them
User avatar
mikeyww
Posts: 26889
Joined: 09 Sep 2014, 18:38

Re: script pixel and image check

20 Feb 2021, 08:39

OK. Are your coordinates relative or absolute?

If you used RGB as the color format, you would need to specify that in the PixelSearch mode.
Green Astronaut
Posts: 84
Joined: 13 Dec 2020, 08:35

Re: script pixel and image check

20 Feb 2021, 16:59

I use screen coordinates,
yes, maybe you are not identifying the color because you did not specify the RGB format
User avatar
mikeyww
Posts: 26889
Joined: 09 Sep 2014, 18:38

Re: script pixel and image check

20 Feb 2021, 19:31

I did not find any B7 values, but you can try adding "RGB" and give it a go.

If you want to use absolute coordinates, you would need to specify that with CoordMode.
Green Astronaut
Posts: 84
Joined: 13 Dec 2020, 08:35

Re: script pixel and image check

21 Feb 2021, 06:44

so I adjusted the script, but I don't know if my code is correct.
can you tell me if i'm doing something wrong?

Code: Select all

#SingleInstance, Force
CoordMode, Pixel, Screen ; need this since you are using screen coordinates
PixelSearch,,, 680, 25, 1000, 40, 0xB7008F, RGB, ; Blue, green, red
If !ErrorLevel
 Return
ImageSearch,,, 530, 578, 580, 600, *50 C:\Usuários\Alex\Desktop\imagens        ; Provide path to image
Send % ErrorLevel ? "" : "{End}"
User avatar
mikeyww
Posts: 26889
Joined: 09 Sep 2014, 18:38

Re: script pixel and image check

21 Feb 2021, 11:47

It looks OK. Your next step is to figure out if each search succeeded or failed. You can add some MsgBox lines to tell you that.
Green Astronaut
Posts: 84
Joined: 13 Dec 2020, 08:35

Re: script pixel and image check

18 Sep 2021, 09:43

I noticed that the search is failing because I determined these pixel search coordinates only on a piece of the bar, and even though the bar is full it checks I'll put an image below to explain it better
User avatar
mikeyww
Posts: 26889
Joined: 09 Sep 2014, 18:38

Re: script pixel and image check

18 Sep 2021, 09:46

If your color 0x8F00B7 is an RGB color, and you add the "RGB" mode, then you would need to adjust your current script accordingly.

An additional error is that you have specified RGB as the variation instead of the mode. It is possible that the two errors have cancelled themselves and do not matter.

When I test pixel searches, I test them without a variation first, to get the basic script working. You want to demonstrate that you can find a pixel of some kind.

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 122 guests