help me to fix this script please

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

help me to fix this script please

23 May 2024, 09:07

I'm trying to create a script that searches for images, but I'm having trouble finding the percentage images. I'll give a brief explanation of how the script works, and if you can help me organize and solve the search problems, I'd be very grateful:

it will first fetch the skull1 image:

If you find it, you will move on to the next searches that are for the variable:

image_uh_name

which in this case is defined by a number from 5 to 100, just multiples of 5, for example: 5, 10, 15, 20 and so on up to 100.

If I set 75 and it finds images below 75 or equal to 75 it executes the action of pressing the "f9" key, if the value of the images found is above 75 it does not perform any action.

Below I will leave the link to the images, remembering that the percentage images are all in PNG and the link I will leave to them below I put them all together to give an example, but they are all separated one by one in the defined folder, each one with its respective name that are numbers.

link img % : https://imgur.com/WoBD3s6

link img skull: https://imgur.com/fWxNH0K

link img skull1: https://imgur.com/hdg9AzZ

Code: Select all

#NoEnv
#Warn
#SingleInstance Force
#MaxHotkeysPerInterval 99000000
#HotkeyInterval 99000000
#KeyHistory 0
SetBatchLines, -1
SendMode Input
SetKeyDelay, -1, -1
SetMouseDelay, 1
SetDefaultMouseSpeed, 1
SetWinDelay, -1
SetControlDelay, -1
CoordMode, Pixel, Screen

; Configuration
uh_hotkey := "{f9}" ; Hotkey to use
battle_coordinates := "x217 y50" ; Coordinates to click
imagem_uh_nome := "75.png" ; Name of the image to search

; Image paths
imagem_uh_path := "C:\Users\miche\OneDrive\Área de Trabalho\" . imagem_uh_nome ; Path to imagem uh.png
skull_path := "C:\Users\miche\OneDrive\Área de Trabalho\skull.png" ; Path to skull.png
skull1_path := "C:\Users\miche\OneDrive\Área de Trabalho\skull1.png" ; Path to skull1.png

SetTimer, CheckHealth, 1000 ; Check every 1 second

While true {
    CheckHealth:
    If WinActive("ahk_class Qt5158QWindowOwnDCIcon")
    {
        ; First Stage [LIFE]
        CoordMode, Pixel, Screen
        CoordSearchMode := "Fast"
        
        ; Search for skull image first
        CoordPixelColor, FoundX, FoundY, 200, 51, PixelGetColor(335, 60), %skull_path%, 0, Fast RGB
        if ErrorLevel = 0
        {
            continue ; Skip to the next iteration of the loop
        }
        
        ; Search for skull1 image
        CoordPixelColor, FoundX, FoundY, 200, 51, PixelGetColor(335, 60), %skull1_path%, 0, Fast RGB
        if ErrorLevel = 0
        {
            continue ; Skip to the next iteration of the loop
        }
        
        ; If skull images not found, then search for the specified image
        CoordPixelColor, FoundX, FoundY, 200, 51, PixelGetColor(335, 60), %imagem_uh_path%, 0, Fast RGB
        if ErrorLevel = 0
        {
            ControlSend,, {f9}, Pokemon
            Sleep 50
            ControlClick, %battle_coordinates%, Pokemon
        }
    }
}

I need to search for all images only within coordinates 180, 32 to 340, 65

Can anyone help me fix this code?
User avatar
kunkel321
Posts: 1194
Joined: 30 Nov 2015, 21:19

Re: help me to fix this script please

23 May 2024, 09:34

Be advised that this

Code: Select all

SetBatchLines, -1
SendMode Input
SetKeyDelay, -1, -1
SetMouseDelay, 1
SetDefaultMouseSpeed, 1
SetWinDelay, -1
SetControlDelay, -1
CoordMode, Pixel, Screen
Looks like it might be formatted as v1 code. v2 usually doesn't have a comma right after the name of the function.
ste(phen|ve) kunkel
gregster
Posts: 9113
Joined: 30 Sep 2013, 06:48

Re: help me to fix this script please

23 May 2024, 09:46

It's clearly v1 code.
Moved topic from AHK v2 gaming help subforum to corresponding v1 subforum since this is not v2 code.
Green Astronaut
Posts: 93
Joined: 13 Dec 2020, 08:35

Re: help me to fix this script please

23 May 2024, 09:51

@kunkel321 I understand, can someone who has experience in v1 code help me? I'm having trouble getting this code to work
Green Astronaut
Posts: 93
Joined: 13 Dec 2020, 08:35

Re: help me to fix this script please

23 May 2024, 13:34

Can someone help me ?
User avatar
kunkel321
Posts: 1194
Joined: 30 Nov 2015, 21:19

Re: help me to fix this script please

23 May 2024, 13:57

Sorry, I'm not sure how to make it work....
ste(phen|ve) kunkel
User avatar
CoffeeChaton
Posts: 44
Joined: 11 May 2024, 10:50

Re: help me to fix this script please

23 May 2024, 21:42

1.
CoordPixelColor is look like a command but it does not exist.
try it https://www.autohotkey.com/docs/v1/lib/ImageSearch.htm

2.
#Warn All, MsgBox
If you are a beginner, it is recommended to turn on the warning, ahk will prompt you where there are common errors, of course the best way is to learn ahk v2 directly.
Green Astronaut
Posts: 93
Joined: 13 Dec 2020, 08:35

Re: help me to fix this script please

24 May 2024, 07:40

Can you show me what it would look like in my script?
Green Astronaut
Posts: 93
Joined: 13 Dec 2020, 08:35

Re: help me to fix this script please

24 May 2024, 11:09

Can anyone help me fix this script?
Green Astronaut
Posts: 93
Joined: 13 Dec 2020, 08:35

Re: help me to fix this script please

24 May 2024, 16:50

I tested and modified the code several times, but I'm having an error on line 34 when running the script, can someone please help me fix this script?

Code: Select all

#NoEnv
#Warn
#SingleInstance Force
#MaxHotkeysPerInterval 99000000
#HotkeyInterval 99000000
#KeyHistory 0
SetBatchLines, -1
SendMode Input
SetKeyDelay, -1
SetMouseDelay, 1
SetDefaultMouseSpeed, 1
SetWinDelay, -1
SetControlDelay, -1
CoordMode, Pixel, Screen

; Configuration
uh_hotkey := "{f9}" ; Hotkey to use
battle_coordinates := "x217 y50" ; Coordinates to click
imagem_uh_nome := "75.png" ; Name of the image to search
valor_limite := 75 ; Upper limit for image value

; Image paths
imagem_uh_path := "C:\Users\miche\OneDrive\Área de Trabalho\" . imagem_uh_nome ; Path to imagem uh.png
skull_path := "C:\Users\miche\OneDrive\Área de Trabalho\skull.png" ; Path to skull.png
skull1_path := "C:\Users\miche\OneDrive\Área de Trabalho\skull1.png" ; Path to skull1.png

SetTimer, CheckHealth, 1000 ; Check every 1 second

CheckHealth:
    IfWinActive, ahk_class Qt5158QWindowOwnDCIcon
    {
        ; First Stage [LIFE]
        CoordMode, Pixel, Screen
        CoordSearchMode, Fast
        
        ; Search for skull image first
        if !ErrorLevel := ImageSearch(FoundX, FoundY, 200, 51, 535, 110, *35, skull_path)
            Goto, ContinueLoop
        
        ; Search for skull1 image
        if !ErrorLevel := ImageSearch(FoundX, FoundY, 200, 51, 535, 110, *35, skull1_path)
            Goto, ContinueLoop
        
        ; If skull images not found, then search for the specified image
        if !ErrorLevel := ImageSearch(FoundX, FoundY, 200, 51, 535, 110, *35, imagem_uh_path)
        {
            ; Get the numerical value from the image filename
            StringReplace, image_value, imagem_uh_nome, .png, 
            ; Compare with the specified value or lower
            if (image_value <= valor_limite)
            {
                ControlSend,, {f9}, Pokemon
                Sleep 50
                ControlClick, %battle_coordinates%, Pokemon
            }
        }
    }
    
ContinueLoop:
Return
gregster
Posts: 9113
Joined: 30 Sep 2013, 06:48

Re: help me to fix this script please

24 May 2024, 16:59

CoordSearchMode, Fast is nothing that AHK would understand. Or did you find it in the docs?
btw, there is no Imagesearch function defined in your code. In AHK v1, Imagesearch is a command, not a function. Of course, you could define one yourself if you prefer it.
Is this a ChatGPT fabrication? It seems to invent stuff like this.

Also, why Goto, ContinueLoop if you could simply return?
Green Astronaut
Posts: 93
Joined: 13 Dec 2020, 08:35

Re: help me to fix this script please

25 May 2024, 00:27

Yes, I was trying to use Chat GPT to fix the code because I don't understand much about it, I'm learning and I can't even read the documentation, I don't know how to put together the code
Green Astronaut
Posts: 93
Joined: 13 Dec 2020, 08:35

Re: help me to fix this script please

26 May 2024, 08:02

help me to fix ?
Green Astronaut
Posts: 93
Joined: 13 Dec 2020, 08:35

imagesearch script help to fix

28 May 2024, 08:19

I need help fixing this script, can anyone help me? I'm learning about the language, and I'm having a lot of difficulty fixing this image search script

Code: Select all

#NoEnv
#Warn
#SingleInstance Force
#MaxHotkeysPerInterval 99000000
#HotkeyInterval 99000000
#KeyHistory 0
SetBatchLines, -1
SendMode Input
SetKeyDelay, -1
SetMouseDelay, 1
SetDefaultMouseSpeed, 1
SetWinDelay, -1
SetControlDelay, -1
CoordMode, Pixel, Screen

; Configuration
uh_hotkey := "{f9}" ; Hotkey to use
battle_coordinates := "x217 y50" ; Coordinates to click
imagem_uh_nome := "75.png" ; Name of the image to search
valor_limite := 75 ; Upper limit for image value

; Image paths
imagem_uh_path := "C:\Users\miche\OneDrive\Área de Trabalho\" . imagem_uh_nome ; Path to imagem uh.png
skull_path := "C:\Users\miche\OneDrive\Área de Trabalho\skull.png" ; Path to skull.png
skull1_path := "C:\Users\miche\OneDrive\Área de Trabalho\skull1.png" ; Path to skull1.png

SetTimer, CheckHealth, 1000 ; Check every 1 second

CheckHealth:
    IfWinActive, ahk_class Qt5158QWindowOwnDCIcon
    {
        ; First Stage [LIFE]
        CoordMode, Pixel, Screen
        CoordSearchMode, Fast
        
        ; Search for skull image first
        if !ErrorLevel := ImageSearch(FoundX, FoundY, 200, 51, 535, 110, *35, skull_path)
            Goto, ContinueLoop
        
        ; Search for skull1 image
        if !ErrorLevel := ImageSearch(FoundX, FoundY, 200, 51, 535, 110, *35, skull1_path)
            Goto, ContinueLoop
        
        ; If skull images not found, then search for the specified image
        if !ErrorLevel := ImageSearch(FoundX, FoundY, 200, 51, 535, 110, *35, imagem_uh_path)
        {
            ; Get the numerical value from the image filename
            StringReplace, image_value, imagem_uh_nome, .png, 
            ; Compare with the specified value or lower
            if (image_value <= valor_limite)
            {
                ControlSend,, {f9}, Pokemon
                Sleep 50
                ControlClick, %battle_coordinates%, Pokemon
            }
        }
    }
    
ContinueLoop:
Return
Last edited by gregster on 28 May 2024, 08:24, edited 1 time in total.
Reason: Merged topics.
gregster
Posts: 9113
Joined: 30 Sep 2013, 06:48

Re: help me to fix this script please

28 May 2024, 08:24

gregster wrote:
24 May 2024, 16:59
CoordSearchMode, Fast is nothing that AHK would understand. Or did you find it in the docs?
btw, there is no Imagesearch function defined in your code. In AHK v1, Imagesearch is a command, not a function. Of course, you could define one yourself if you prefer it.
[...]

Also, why Goto, ContinueLoop if you could simply return?
Why didn't you work on these hints? 🤷‍♂️
If you get error messages, you could at least look up the commands in the mentioned docs, follow the examples and make an attempt to fix the mistakes. This is the way to learn programming.

I can't even read the documentation
how is that?
I mean if I get an error message like "Error at line 34. Line Text: CoordSearchMode, Fast - Error: This line does not contain a recognized action", I would check the docs and find out that CoordSearchMode doesn't exist as a command - and should be removed.
And if I get "Error: Call to nonexistent function. Specifically: ImageSearch(FoundX, FoundY, 200, 51, 535, 110, *35, skull_path)", I'll look up the syntax for Imagesearch. Even if I don't understand everything, the examples would tell me that I need to change some things: https://www.autohotkey.com/docs/v1/lib/ImageSearch.htm#Examples

Start small, with just a few lines; for example, try a single Imagesearch and check its result. Compare https://www.autohotkey.com/docs/v1/lib/ImageSearch.htm#ExScreen When you got that code working, expand it. If you get problems, post your code and ask in these forums, but please don't post non-working ChatGPT code again. It's not a good way to learn, especially if you don't check it against the documentation.

btw, AI doesn't generate any good AHK code yet and invents a lot of nonsense. This wastes everybody's time an that's why it is currently not allowed on these forums (see forum rules). Usually, we just delete such code - and I get the impression that I should have done that here as well, if it keeps you from working on the code yourself.

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: mexican scientist and 73 guests