how do you make && operator for pixelgetcolor? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ravena1
Posts: 62
Joined: 06 Sep 2017, 15:13

how do you make && operator for pixelgetcolor?

24 Feb 2022, 19:03

im little bit confused with && operator? can you guys help me? thanks

Code: Select all

square2()  {
       
         PixelSearch, X, Y, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, 0x00ff00, 0, fast
	 PixelGetColor, yellow, 25, 39, RGB
        
	if yellow = 0xFFFF63 && ErrorLevel=0  {
        MsgBox You found square2
	sleep, 100
	return
  }
	
     else {
     sleep, 500
     return
   }
    
}
User avatar
mikeyww
Posts: 27271
Joined: 09 Sep 2014, 18:38

Re: how do you make && operator for pixelgetcolor?

24 Feb 2022, 19:18

Here are some ideas.

Code: Select all

x := 25, y := 39

Square2:
WinGetPos,,, winWidth, winHeight, A
MouseMove, x, y
PixelGetColor, rgb, x, y, RGB
PixelSearch,,, 0, 0, winWidth, winHeight, 0x00FF00,, Fast
err := ErrorLevel
WinGetActiveTitle, wTitle
MsgBox, 64, %wTitle%, ErrorLevel (search) = %err%`n`nrgb (%x%`, %y%)           = %rgb%
If !err && rgb = 0xFFFF63 {
 MsgBox, You found square2
 Sleep, 100
} Else Sleep, 500
Return
ravena1
Posts: 62
Joined: 06 Sep 2017, 15:13

Re: how do you make && operator for pixelgetcolor?

27 Feb 2022, 14:57

will this be fine?

Code: Select all

square2()  {
Global
        PixelSearch, X, Y, 66, 65, 120, 106, 0xF90200, 0, fast
	PixelGetColor, yellow, 25, 39, RGB
        err := ErrorLevel
	if !err && yellow = 0xFFFF63 { 

        ControlSend, ahk_parent, !0, ahk_pid %AhkPID%
        sleep, 200
	ControlSend, ahk_parent, {F9}, ahk_pid %AhkPID%
        soundbeep, 750, 2500
	sleep, 9000
        ControlSend, ahk_parent, !0, ahk_pid %AhkPID%
        sleep, 200
	return
  }
	
     else {
     sleep, 20
     return
	 }
 }
   
Last edited by ravena1 on 27 Feb 2022, 17:11, edited 1 time in total.
User avatar
mikeyww
Posts: 27271
Joined: 09 Sep 2014, 18:38

Re: how do you make && operator for pixelgetcolor?

27 Feb 2022, 14:58

What happened when you tried it? Is your indentation random, or is there some sort of pattern to it?
ravena1
Posts: 62
Joined: 06 Sep 2017, 15:13

Re: how do you make && operator for pixelgetcolor?

28 Feb 2022, 05:24

i have wierd issue

i try to debug it
yellow = 0xFFFF63 works fine
but
!err did not work and it seems ignores it completely

funny thing is i even hide the color from pixelsearch and only yellow from pixelgetcolor visible to my screen but still it says found :lol:

Code: Select all

        err := ErrorLevel
	if !err && yellow = 0xFFFF63 { 
         SplashTextOn,,, found!
         Sleep 2000
        SplashTextOff
User avatar
boiler
Posts: 17304
Joined: 21 Dec 2014, 02:44

Re: how do you make && operator for pixelgetcolor?  Topic is solved

28 Feb 2022, 05:32

By assigning ErrorLevel to err after the PixelGetColor, it is always going to be 0 because PixelGetColor sets it (and almost never has an error), so it has nothing to do with the result of the PixelSearch. Move the assignment after the PixelSearch and prior to PixelGetColor, or put the order of the PixelGetColor and the PixelSearch lines the way mikeyww had it.
ravena1
Posts: 62
Joined: 06 Sep 2017, 15:13

Re: how do you make && operator for pixelgetcolor?

28 Feb 2022, 05:38

boiler wrote:
28 Feb 2022, 05:32
By assigning ErrorLevel to err after the PixelGetColor, it is always going to be 0 because PixelGetColor sets it (and almost never has an error), so it has nothing to do with the result of the PixelSearch. Move the assignment after the PixelSearch and prior to PixelGetColor, or put the order of the PixelGetColor and the PixelSearch lines the way mikeyww had it.
it working now.. thank u

Code: Select all

        PixelGetColor, yellow, 166, 101, RGB
        PixelSearch, X, Y, 322, 74, 381, 86, 0xFFFFFF, 0, fast
        err := ErrorLevel
	if !err && yellow = 0x8CE7A5 { 
User avatar
boiler
Posts: 17304
Joined: 21 Dec 2014, 02:44

Re: how do you make && operator for pixelgetcolor?

28 Feb 2022, 05:43

I second mikeyww’s question about your indentation, I suggest you adopt an approach that represents the logical flow of your code. The haphazard nature of the way your code is indented makes it hard for others to follow, and is actually a bit unsettling to look at.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: doanmvu, peter_ahk and 193 guests