Jump to content

PixelGetColor in dynamic array not working


Recommended Posts

Hello,

I've been using AutoIt off and on since I was about 13 years old, but this is the first time I've been really stumped about a bug in one of my scripts.

This is the part of my code that isn't running as I intended. It is supposed to get the number of rows in a table (up to a max of 9). 

Each row is 40 pixels apart on the y axis. And sometimes a row will be skipped if it isn't the color I'm looking for. 

No matter what I do, the output in tooltip is always 9. The variable $pc shouldn't be increasing unless the $hparr variable matches one of two colors. 

#RequireAdmin
Global $i = 0
Global $hparr[10]
Global $p[2]
Global $pc

$dt = TimerInit()

While 1
        ;; Check Table Size
        $pc = 1
        $i = 1
        $p[0] = 64  ;49
        $p[1] = 106 ;93
        Do
            $i += 1
            $p[1] += 40
            $hparr[$i] = PixelGetColor($p[0],$p[1])
            If $hparr[$i] = 16768669 or 15849372 Then $pc += 1
        Until $i = 9
        $i = 0
        ;; delay at random
        $delay = Random ( 150, 355 )
        $dtt = TimerDiff($dt)
        While $dtt < $delay
            $dtt = TimerDiff ($dt)
        WEnd
        $dt = TimerInit()
                ToolTip ("This section is showing: " & $pc & " rows")
Wend
Edited by MarksRobert
Link to comment
Share on other sites

you can use my func for detect pixel:

#include <WinAPI.au3>
Func DETECTPIXEL($x, $Y, $colpix)
    Local $l1, $Clr
    $wingethandle = WinGetHandle($nameapp)
    $l1 = _WinAPI_GetDC($wingethandle)
    $Clr = _WinAPI_GetPixel($l1, $x, $Y)
    If Hex($Clr, 6) = $colpix Then
        _WinAPI_ReleaseDC($wingethandle, $l1)
        _WinAPI_DeleteDC($nameapp)
         Return 1
     EndIf
     Return 0
EndFunc   ;==>DETECTPIXEL

It return 1 if pixel is found and 0 otherwise

After your script you can call as: If  DETECTPIXEL($p[0],$p[1]),Hex(16768669)) = 1 or DETECTPIXEL($p[0],$p[1]),Hex(15849372)) Then $pc += 1

Edited by DocTorCoder

DocTorCoder

Link to comment
Share on other sites

DocTorCoder:

Thanks I was thinking about a similar workaround and this will work very well.

But more than anything, I'm curious as to why my script isn't working? These are all functions that I'm very familiar with, and to have an unexpected result tells me I'm not understanding something.

Can you, or anyone else reading this, tell me if there is some limit of the functions that prevents what I was trying to do in my original script?
 

In the meantime, I'll be using your workaround. :-)

 

EDIT: Wow, I am careless. I found the problem. I used the OR logical operator incorrectly. I needed to restate the variable like this:

If $hparr[$i] = 16768669 Or $hparr[$i] = 15849372 Then $playercount += 1

NOT like this:

If $hparr[$i] = 16768669 Or 15849372 Then $playercount += 1

The difference is that the latter is interpreted as: "If this color is gold OR if 15849372 = 15849372 then do this.

Edited by MarksRobert
Link to comment
Share on other sites

DocTorCoder:

Thanks I was thinking about a similar workaround and this will work very well.

But more than anything, I'm curious as to why my script isn't working? These are all functions that I'm very familiar with, and to have an unexpected result tells me I'm not understanding something.

Can you, or anyone else reading this, tell me if there is some limit of the functions that prevents what I was trying to do in my original script?

 

In the meantime, I'll be using your workaround. :-)

 

EDIT: Wow, I am careless. I found the problem. I used the OR logical operator incorrectly. I needed to restate the variable like this:

If $hparr[$i] = 16768669 Or $hparr[$i] = 15849372 Then $playercount += 1

NOT like this:

If $hparr[$i] = 16768669 Or 15849372 Then $playercount += 1

The difference is that the latter is interpreted as: "If this color is gold OR if 15849372 = 15849372 then do this.

I didnt notice that mistake too (I was blind - so that if was useless because 15849372 is always equal with 15849372).I'm glad you solve the problem and now you have 2 versions. You can use which one you think is better or who accomplish your desire.

Enjoy !

DocTorCoder

Edited by DocTorCoder

DocTorCoder

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...