Pixelgetcolor not working?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Derick
Posts: 2
Joined: 06 Sep 2018, 03:01

Pixelgetcolor not working?

05 Jul 2019, 00:06

Hello! I'm having a problem getting the pixelgetcolor function to work properly. I'm using it 5 times in my script but it only seems to work once.. I've tried using different variables and I've tried reusing the same with no help. Here's my script:


--------------------------------------------------------------------

Code: Select all

pause on
#singleinstance, force
coordmode, mouse, screen
coordmode, pixel, screen
setdefaultmousespeed, 3

;;this only works with bluestacks in full sized windowed mode.  not fullscreen



msgbox, 0, 0, Go
Loop
{
Loop 40
	{
	;get encounter
		click, 360, 390
		sleep, 300
		Click, 360, 390, Left, down ; press the LMD and hold it
		Click, 360, 490, Left, 0 ; move the mouse and click zero times (aka, move only)
		sleep, 5000
		Pixelgetcolor, color, 430, 164
		if (color = 0x000000)
		{
			break
		}
	}
	
	click, 260, 390 
	sleep, 2000



;fight encounter

	click, 272, 868, 4       ;instinct subsect
	sleep, 400
	click, 500, 860, 4       ; sharpen ability
	sleep, 5500                      ;delay for combat scene
loop 4
{
	sleep, 2000
	click, 260, 930, 4       ;weapons tab
	sleep, 400
	loop 2 
		{
		click, 500, 860, 4       ;attack
		sleep, 5500         
		}
	click, 260, 800, 4         ;control tab
	sleep, 400
	click, 1050, 900, 1        ;petrify
	sleep, 400
	click, 260, 930. 4			;weapons tab
	sleep, 500
	click, 830, 900, 9         ;heavy hit
	sleep, 600
	click, 1600, 900, 6			;go
	sleep, 14500
	pixelgetcolor, endd, 1064, 71
	if (endd = 0x1C1C1C)
		{
			break
		}
	pixelgetcolor, gold1, 541, 350  [, RGB]
	if (gold1 = 0x000000)
		{
			break
		}
	pixelgetcolor, expad1, 1386, 220  [, RGB]
	if (expad1 = 0x000000)
		{
			break
		}
}
	sleep, 1200


;claim rewards
	pixelgetcolor, gold, 716, 360  [, slow RGB]
	if (gold = 0x825511)
		{
			click, 728, 756, 3            ;accept gold 3x offer
		}
	pixelgetcolor, expad, 1015, 395  [, slow RGB]
	if (expad = 0x664D45)
		{
			click, 728, 756, 3            ;accept exp 3x offer
		}
	
	click, 1080, 730, 5			;skip offer
	sleep, 900
	click, 1080, 730, 3			;speed up screen
	sleep, 3700
	click, 1380, 260, 5			;close window
	sleep, 900
	click, 780, 600, 5			;confirm tossing item drops
	sleep, 1400
	
}


exitapp
!z::exitapp
!8::pause
----------------------------------------------------------------------


My first use of pixelgetcolor followed by if(xx){break} works beautifully to break the loop and move onto the next section. None of the rest work at all, and wont break the immediate loop they're a part of when they should be true. I'm using windowspy to track pixel colors at certain mousecoords under the circumstances it should trigger in. The game its for has very simple 2D graphics with no shading or anything so I dont see why this shouldn't be working. Any advice? Thanks.
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Pixelgetcolor not working?

05 Jul 2019, 01:30

Lets fix the obvious 1st
[, RGB] <-- the square brackets means whats between them its optional.
Do not include the [ ] in the code.

pixelgetcolor, gold1, 541, 350 [, RGB]
would be: (if you want to use the RGB optional parameter)
pixelgetcolor, gold1, 541, 350, RGB

etc etc

This is pretty consistent in the documentation for each command / function
HTH
nou
Posts: 26
Joined: 24 Feb 2019, 21:21

Re: Pixelgetcolor not working?

05 Jul 2019, 03:10

When in doubt, check your variables. Use tooltip/msgbox.

Code: Select all

pause on
#singleinstance, force
coordmode, mouse, screen
coordmode, pixel, screen
setdefaultmousespeed, 3

;;this only works with bluestacks in full sized windowed mode.  not fullscreen

halfx := A_ScreenWidth // 2
halfy := A_ScreenHeight //2 

msgbox, 0, 0, Go

Loop
{
    Loop 40
    {
        ;get encounter
        
        click, 360, 390
        sleep, 300

        ; press the LMD and hold it
        Click, 360, 390, Left, down

        ; move the mouse and click zero times (aka, move only)
        Click, 360, 490, Left, 0
        sleep, 5000

        Pixelgetcolor, color, 430, 164
        if (color = 0x000000)
            break
    }
    
    click, 260, 390
    sleep, 2000
       
    ;fight encounter
       
    ;instinct subsect
    click, 272, 868, 4
    sleep, 400

    ; sharpen ability
    click, 500, 860, 4

    ;delay for combat scene
    sleep, 5500

    loop 4
    {
        sleep, 2000
        ;weapons tab
        
        click, 260, 930, 4
        sleep, 400

        loop 2
        {
            ;attack
            click, 500, 860, 4
            sleep, 5500
        }

        ;control tab
        click, 260, 800, 4
        sleep, 400

        ;petrify
        click, 1050, 900, 1
        sleep, 400
        
        ;weapons tab
        click, 260, 930. 4
        sleep, 500
        
        ;heavy hit
        click, 830, 900, 9
        sleep, 600
        
        ;go
        click, 1600, 900, 6
        sleep, 14500
        
        pixelgetcolor, endd, 1064, 71 , RGB
        pixelgetcolor, gold1, 541, 350  , RGB
        pixelgetcolor, expad1, 1386, 220  , RGB

        ToolTip % "loop count: " A_Index "`n"
            . "endd value = " endd "`n" 
            . "gold1 value = " gold1 "`n" 
            . "expad1 value = " expad1, % halfx, 0, 2

        if (endd = 0x1C1C1C) || (gold1 = 0x000000) || (expad1 = 0x000000)
        {
            break
        }
    }

    sleep, 1200
       
    ;claim rewards
    
    pixelgetcolor, gold, 716, 360  , slow RGB
    ToolTip, % "Loop count: " A_Index "`nGold Value = " gold "`n" "Need to match 0x825511", % A_ScreenWidth - 40, 0, 3


    if (gold = 0x825511)
    {
        ;accept gold 3x offer
        click, 728, 756, 3
    }

    
    pixelgetcolor, expad, 1015, 395  , slow RGB
    ToolTip, % "Loop count: " A_INdex "`n" "expad Value = " expad "`n" "Need to match 0x664D45", % A_SCreenWidth - 40, 80, 4

    if (expad = 0x664D45)
    {
        ;accept exp 3x offer
        click, 728, 756, 3
    }
    
    ;skip offer
    click, 1080, 730, 5
    sleep, 900

    ;speed up screen
    click, 1080, 730, 3
    sleep, 3700
    
    ;close window
    click, 1380, 260, 5
    sleep, 900
    
    ;confirm tossing item drops
    click, 780, 600, 5
    sleep, 1400
    
}


exitapp
!z::exitapp
!8::pause

Derick
Posts: 2
Joined: 06 Sep 2018, 03:01

Re: Pixelgetcolor not working?

05 Jul 2019, 03:12

Haha, yea you're right. It's been a while since I've done anything with AHK.. I kind of forgot how to read the documentation. After removing the brackets, I still face the same problem, however. Actually, I've removed the RGB as well and simply edited my If statement to look for the BGR value of the color instead, removing the need for it.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, cleetz, Google [Bot], Kellyzkorner_NJ and 51 guests