Script that checks state of pixel, but uses 2 states to determine output

Ask gaming related questions (AHK v1.1 and older)
imbelicalcord
Posts: 4
Joined: 05 May 2024, 12:05

Script that checks state of pixel, but uses 2 states to determine output

05 May 2024, 12:07

So i got a script i am making for a game, it checks if spot 2 in occupied if it is, it continues the script, if its not it breaks and continues its on a Loop function, problem is sometimes the first spot can be empty first before the second one is empty, how do i make it so it checks both values and works together, here is the code i tried but it didnt work since obviously spot 2 is still occupied and as such it doesn't break the loop.

Code: Select all

Loop ; Checks if the item is in inventory 2nd spot
        {      ; Checks if second spot is occupied
            PixelSearch, px, py, 629, 251, 636, 256, 0x39414A, 0, Fast ; Searches for the color of the chat box or the craft menu in top right
             if (!ErrorLevel = 0) ; If the color matches to the one above, proceed with the script               
                {
                        {
                            continue ; If the item is in inventory continue
                            sleep 10
                        }
                }
                else ; If the item is not in the inventory
                {
                     Random, s1, 300, 500 ; Generates a value between (x, x) in miliseconds to sleep
                     sleep %s1% ; Sleeps for a random value between 300 - 500 as specified above
                     Break ; Breaks the loop if the color matched
                     sleep 10
                }
        }

        Loop ; Checks if item is in inventory 1st spot
            {
                PixelSearch, px, py, 584, 251, 591, 261, 0x39414A, 0, Fast ; Searches for the color of the chat box or the craft menu in top right
                if (!ErrorLevel = 0) ; If the color matches to the one above, proceed with the script
                    {
                        continue ; If the item is in inventory continue
                        sleep 10
                    }
                    else ; If the item is not in the inventory
                    {
                         Random, s1, 300, 500 ; Generates a value between (x, x) in miliseconds to sleep
                         sleep %s1% ; Sleeps for a random value between 300 - 500 as specified above
                         Break ; Breaks the loop if the color matched
                         sleep 10
                    }
            }

[Mod action: Moved topic to the “Gaming” section.]
User avatar
mikeyww
Posts: 27165
Joined: 09 Sep 2014, 18:38

Re: Script that checks state of pixel, but uses 2 states to determine output

05 May 2024, 12:32

Welcome to this AutoHotkey forum!

You can search twice in sequence. Use different variables.

If you are new to AHK, I recommend using its current version, which is v2, instead of this older deprecated version that is no longer developed.
imbelicalcord
Posts: 4
Joined: 05 May 2024, 12:05

Re: Script that checks state of pixel, but uses 2 states to determine output

05 May 2024, 12:57

mikeyww wrote:
05 May 2024, 12:32
Welcome to this AutoHotkey forum!

You can search twice in sequence. Use different variables.

If you are new to AHK, I recommend using its current version, which is v2, instead of this older deprecated version that is no longer developed.
I tried something along the lines of

Code: Select all

       Loop ; Checks if the item is in inventory 2nd spot
        {      ; Checks if second spot is occupied
            PixelSearch, px, py, 629, 251, 636, 256, 0x39414A, 0, Fast ; Searches for the color of the chat box or the craft menu in top right
             if (!ErrorLevel = 0) ; If the color matches to the one above, proceed with the script               
                {      ; Checks if first spot is occupied
                    PixelSearch, px, py, 584, 251, 591, 261, 0x39414A, 0, Fast ; Searches for the color of the chat box or the craft menu in top right
                    if (!ErrorLevel = 0) ; If the color matches to the one above, proceed with the script
                        { 
                            continue ; If the item is in inventory continue
                            sleep 10
                        }
                }
                else ; If the item is not in the inventory
                {
                     Random, s1, 300, 500 ; Generates a value between (x, x) in miliseconds to sleep
                     sleep %s1% ; Sleeps for a random value between 300 - 500 as specified above
                     Break ; Breaks the loop if the color matched
                     sleep 10
                }
        }
and

Code: Select all

       Loop ; Checks if the item is in inventory 2nd spot
        {
            PixelSearch, px, py, 629, 251, 636, 256, 0x39414A, 0, Fast ; Searches for the color of the chat box or the craft menu in top right
             if (!ErrorLevel = 0) ; If the color matches to the one above, proceed with the script               
                {
                    PixelSearch, px, py, 584, 251, 591, 261, 0x39414A, 0, Fast ; Searches for the color of the chat box or the craft menu in top right
                    if (!ErrorLevel = 0) ; If the color matches to the one above, proceed with the script    
                    continue ; If the item is in inventory continue
                    sleep 10
                }
                else ; checks if first item is in inventory
                {
                    PixelSearch, px, py, 584, 251, 591, 261, 0x39414A, 0, Fast ; Searches for the color of the chat box or the craft menu in top right
                    if (!ErrorLevel = 0) ; If the color matches to the one above, proceed with the script               
                        {
                           continue ; If the item is in inventory continue
                           sleep 10
                        }
                }
                else ; If the item is not in the inventory
                {
                     Random, s1, 300, 500 ; Generates a value between (x, x) in miliseconds to sleep
                     sleep %s1% ; Sleeps for a random value between 300 - 500 as specified above
                     Break ; Breaks the loop if the color matched
                     sleep 10
                }
        }
first one doesn't give me error but doesn't work, almost as if it doesn't do anything after the action in the game has finished for the second spot, it just stops
second one gives me an error for ''missing if argumeny for ''else', im pretty new yes and i am using 1.1 since i am not sure how to do !errorlevel in the newer version as i need to use that
User avatar
mikeyww
Posts: 27165
Joined: 09 Sep 2014, 18:38

Re: Script that checks state of pixel, but uses 2 states to determine output

05 May 2024, 13:02

What is your belief about what the following code does?

Code: Select all

If (!ErrorLevel = 0)
Do you believe that it differs from the following, or is the same?

Code: Select all

If (ErrorLevel = 0)
imbelicalcord
Posts: 4
Joined: 05 May 2024, 12:05

Re: Script that checks state of pixel, but uses 2 states to determine output

05 May 2024, 14:54

mikeyww wrote:
05 May 2024, 13:02
What is your belief about what the following code does?

Code: Select all

If (!ErrorLevel = 0)
Do you believe that it differs from the following, or is the same?

Code: Select all

If (ErrorLevel = 0)
I am not sure to be honest, I am going off of previous iterations which has that, so i just stuck with it, mind explaining the difference, since i couldnt find it in the documentation for 1.1
User avatar
mikeyww
Posts: 27165
Joined: 09 Sep 2014, 18:38

Re: Script that checks state of pixel, but uses 2 states to determine output

05 May 2024, 21:31

I would go with this example.

https://www.autohotkey.com/docs/v1/lib/PixelSearch.htm#ExBasic
ErrorLevel is set to 0 if the color was found in the specified region, 1 if it was not found, or 2 if there was a problem that prevented the command from conducting the search.
Source: PixelSearch - Syntax & Usage | AutoHotkey v1
Have a look at this documentation page. As noted, if the ErrorLevel is zero, then the color was found. ! means NOT.
imbelicalcord
Posts: 4
Joined: 05 May 2024, 12:05

Re: Script that checks state of pixel, but uses 2 states to determine output

06 May 2024, 00:31

mikeyww wrote:
05 May 2024, 21:31
I would go with this example.

https://www.autohotkey.com/docs/v1/lib/PixelSearch.htm#ExBasic
ErrorLevel is set to 0 if the color was found in the specified region, 1 if it was not found, or 2 if there was a problem that prevented the command from conducting the search.
Source: PixelSearch - Syntax & Usage | AutoHotkey v1
Have a look at this documentation page. As noted, if the ErrorLevel is zero, then the color was found. ! means NOT.
wait so what would the combination of ! and 0 do? since 0 is found and ! is not found, this works in the script for what its supposed to do so i am a tad bit confused,
User avatar
boiler
Posts: 17180
Joined: 21 Dec 2014, 02:44

Re: Script that checks state of pixel, but uses 2 states to determine output

06 May 2024, 02:07

imbelicalcord wrote: wait so what would the combination of ! and 0 do?
!0 (meaning “not 0” or “not false”) is 1 or true, and !1 is 0 or false.

imbelicalcord wrote: since 0 is found and ! is not found, this works in the script for what its supposed to do so i am a tad bit confused,
No, ! does not mean “not found”, it just means “not”. It flips the “truthiness” result of whatever you apply it to. It flips true to false and false to true. It doesn’t have a value itself. So when you are checking the result of !ErrorLevel, that result would then be 1 when a pixel of the target color is found and 0 when it is not found.

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 36 guests