help to fix guys

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Green Astronaut
Posts: 84
Joined: 13 Dec 2020, 08:35

help to fix guys

Post by Green Astronaut » 29 Nov 2022, 08:05

I need help with this code below, it just presses the {f5} key when it finds the color LightgreenColor

Code: Select all

#Persistent
#SingleInstance, Force
CoordMode, Pixel, Screen
Loop {
WinWaitActive, Pokemon
SetTimer, Check
WinWaitNotActive
SetTimer, Check, Off
}
Check:
PixelSearch,,, 199, 50, 334, 50, 0x707070,, Fast
If !ErrorLevel
Return
PixelGetColor, GreenColor, 320, 50, RGB
If (GreenColor = 0x00C000)
Return
PixelGetColor, LightgreenColor, 310, 50, RGB
PixelGetColor, YellowColor    , 255, 50, RGB
PixelGetColor, RedColor       , 235, 50, RGB
If (LightgreenColor != 0x60C060 And YellowColor != 0xC0C000 And RedColor != 0xC03030)
ControlSend,, {f5}, Pokemon
Return
in this case I need the {f5} key to be pressed whenever I find the colors below:
If (LightgreenColor != 0x60C060 And YellowColor != 0xC0C000 And RedColor != 0xC03030)

but only if they are within the specified coordinate below:

201, 46 to 311, 55

Can someone help me ?

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

Re: help to fix guys

Post by mikeyww » 29 Nov 2022, 08:07

You could PixelSearch for each color, and then act on the result of each search, or on the results of all searches together. The result of each search can be saved in a unique variable. An example of PixelSearch is on line 11 of your script.

Green Astronaut
Posts: 84
Joined: 13 Dec 2020, 08:35

Re: help to fix guys

Post by Green Astronaut » 29 Nov 2022, 15:34

got it, can you help me to make act in all the research?


if possible, I need him to search the 3 colors below only in the coordinates
201, 46 to 311, 55

I need you to look for these colors below.

ColorHP := ["0x00C000", "0x60C060", "0xC0C000", "0xC03030", "0x00BF00", "0x60BF60", "0xBFBF00", "0xBF3030"]


would it be possible to search for all of them?

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

Re: help to fix guys

Post by mikeyww » 29 Nov 2022, 15:50

For the three colors that you want:
1. Conduct the search for one color, like you did in your script.
2. Save the ErrorLevel to a variable.
3. Repeat #1 and #2 until done.
4. Issue an If statement, like you did in your script.

Green Astronaut
Posts: 84
Joined: 13 Dec 2020, 08:35

Re: help to fix guys

Post by Green Astronaut » 29 Nov 2022, 16:20

I don't know very well how to do this, I had your help to create this code

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

Re: help to fix guys

Post by mikeyww » 29 Nov 2022, 16:23

Your goal has not been clearly stated yet. Are there three colors, or more than three? What should happen after the search is conducted?

Green Astronaut
Posts: 84
Joined: 13 Dec 2020, 08:35

Re: help to fix guys

Post by Green Astronaut » 29 Nov 2022, 18:17

instead of looking for just 3 colors, I decided to look for all of these below:
ColorHP := ["0x60C060", "0xC0C000", "0xC03030", "0x60BF60", "0xBFBF00", "0xBF3030"]

to have a better chance of succeeding the search.
and when any of these colors are found within the coordinate 201, 46 to 311, 55

press the {f5} key

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

Re: help to fix guys

Post by mikeyww » 29 Nov 2022, 19:01

Code: Select all

Check:
For each, bgr in [0x60C060, 0x00C0C0, 0x3030C0, 0x60BF60, 0x00BFBF, 0x3030BF] {
 PixelSearch,,, 201, 46, 311, 55, bgr,, Fast
 Send % ErrorLevel ? "" : "{F5}"
}
Return

Green Astronaut
Posts: 84
Joined: 13 Dec 2020, 08:35

Re: help to fix guys

Post by Green Astronaut » 29 Nov 2022, 19:40

I did the test here, but it ends up finding some of the colors outside the coordinate I specified and ends up pressing the {F5} key

it would be possible to do the following.
take no action if you find any of the colors below. Just skip to next check.

exemple: if you find any of these colors within the coordinate
201, 46, 311, 55
proceed to the next scan without taking any action
0x707070
0x00C000
0x00BF00
0x454545
0x4B4B4B
0x494949
0x484848
0x464646
0x4D4D4D


and the next check would be:
if you find any of these colors within the coordinate
[0x60C060, 0x00C0C0, 0x3030C0, 0x60BF60, 0x00BFBF, 0x3030BF]
201, 46, 311, 55
press {f5}

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

Re: help to fix guys

Post by mikeyww » 29 Nov 2022, 20:58

Ends up finding some of the colors outside the coordinate I specified
You are mistaken, though you might have specified the wrong coordinates if you are not referring to the coordinates relative to the active window. Adding a MouseMove to the found coordinates will prove that for you.

You have more than 80 posts, including some that refer to arrays, searches, sending keys, and conditional statements, as well as complete scripts. I hereby anoint you an AutoHotkey Programmer. You now have the full power to use any of the commands that have already been posted in this thread by you or others, including waiting for windows, looping, searching for pixels, and sending keys. As an extra bonus, you have also earned the right to use other AHK commands. :)

With these new powers, you can try your hand. You have all of the code examples right here. You can conduct individual pixel searches, one by one, without any need to use an array. The ErrorLevel tells you if the search succeeded. If you get stuck, you can post your script to get help with it. Have at it!

Tip: start with one search, using coordinates relative to the active window. After the search, save the ErrorLevel as a variable, and display it. After that works, you can then build the script from there.

Another tip: in plain language, write the steps that you want to happen, step by step, in detail, in sequence. That can ease the coding process. You have a head start with your last post.

Post Reply

Return to “Ask for Help (v1)”