So you can see that variable $track is the pixel that will be tracked, and it could be any of the 8 different colors ($pixel,$pixel2,$pixel3...$pixel8). But the script checks which of the 8 pixel colors has the lowest X value and assigns this value to variable $track which will later be used for tracking.

The problem here is that not every $pixel variable is present on the screen at the same time, so I get the error "non-accessible variable" when the script is performing the "if var1 x < var2 x". I understand why this results in an error but I've hit a wall in how to continue. Can those variables that are not present be ignored so that there is no error? How to check for which has the smallest x value from those that are present?

I also understand that I can do "if isarray($pixel) =true and isarray($pixel2)=true then if $pixel<$pixel2 then $track=$pixel" so split it up into every possibility to include a check for array but that would result in so much at least 64 different checks or more for every possible combination, there must be a simpler way.

Share this post

Link to post

Share on other sites

wizardpug 0

wizardpug 0

I'm not familiar with arraysort and I'm probably using it wrong. I followed your recipe and then to check if it's doing what we want, I did a mousmove to $aResult[0][0], $aResult[0][1] but it doesn't move to the leftest point and stop, instead it jumps around from point to point. Here it is:

$MousePos=MouseGetPos()Local$aResult[8][2],$n=0$pixel=PixelSearch($MousePos[0]-100,$MousePos[1]-200,$MousePos[0]+100,$MousePos[1]+100,0xC739AF,30)Ifnot@errorThen; to avoid the "non-accessible variable" error$aResult[$n][0]=$pixel[0]$aResult[$n][1]=$pixel[1]$n+=1EndIf$pixel2=PixelSearch($MousePos[0]-100,$MousePos[1]-200,$MousePos[0]+100,$MousePos[1]+100,0xE356C6,30)Ifnot@errorThen; to avoid the "non-accessible variable" error$aResult[$n][0]=$pixel2[0]$aResult[$n][1]=$pixel2[1]$n+=1EndIf$pixel3=PixelSearch($MousePos[0]-100,$MousePos[1]-200,$MousePos[0]+100,$MousePos[1]+100,0x9D2897,30)Ifnot@errorThen; to avoid the "non-accessible variable" error$aResult[$n][0]=$pixel3[0]$aResult[$n][1]=$pixel3[1]$n+=1EndIf$pixel4=PixelSearch($MousePos[0]-100,$MousePos[1]-200,$MousePos[0]+100,$MousePos[1]+100,0xDC47B1,30)Ifnot@errorThen; to avoid the "non-accessible variable" error$aResult[$n][0]=$pixel4[0]$aResult[$n][1]=$pixel4[1]$n+=1EndIf$pixel5=PixelSearch($MousePos[0]-100,$MousePos[1]-200,$MousePos[0]+100,$MousePos[1]+100,0xE255C5,30)Ifnot@errorThen; to avoid the "non-accessible variable" error$aResult[$n][0]=$pixel5[0]$aResult[$n][1]=$pixel5[1]$n+=1EndIf$pixel6=PixelSearch($MousePos[0]-100,$MousePos[1]-200,$MousePos[0]+100,$MousePos[1]+100,0xDB46B0,30)Ifnot@errorThen; to avoid the "non-accessible variable" error$aResult[$n][0]=$pixel6[0]$aResult[$n][1]=$pixel6[1]$n+=1EndIf$pixel7=PixelSearch($MousePos[0]-100,$MousePos[1]-200,$MousePos[0]+100,$MousePos[1]+100,0xDB47B0,30)Ifnot@errorThen; to avoid the "non-accessible variable" error$aResult[$n][0]=$pixel7[0]$aResult[$n][1]=$pixel7[1]$n+=1EndIf$pixel8=PixelSearch($MousePos[0]-100,$MousePos[1]-200,$MousePos[0]+100,$MousePos[1]+100,0xE255C6,30)Ifnot@errorThen; to avoid the "non-accessible variable" error$aResult[$n][0]=$pixel8[0]$aResult[$n][1]=$pixel8[1]$n+=1EndIfRedim$aResult[$n][2]_ArraySort($aResult)

Share this post

Link to post

Share on other sites

mikell 610

mikell 610

May I suggest, have a look at the helpfile to learn how _ArraySort works (parameters !! )
Then use _ArrayDisplay before and after the sorting to check the result and the coordinates with the lowest x. If these coordinates are the correct ones then it's a trouble when using MouseMove

Share this post

Link to post

Share on other sites

wizardpug 0

wizardpug 0

yes the first arraydisplay gives me 7 rows, col0 and col1 columns that are empty, second arraydisplay which is after sort has 7 columns with col0 at 600-605 not in order and col1 all at 230. Col0 is x axis? It looks like arraysort doesn't sort it by x in my script?

Share this post

Link to post

Share on other sites

mikell 610

mikell 610

the first arraydisplay gives me 7 rows, col0 and col1 columns that are empty, second arraydisplay which is after sort has 7 columns with col0 at 600-605 not in order and col1 all at 230.

Well, I can't see the logic in there. If the first array is empty, the second one would not fill up magically.

Here is the concept I suggested in post #4 :
- pixelsearch returns x and y coordinates in a 1D array
- these coordinates if exist are stored in the $aResult 2D array. col0 = x, col1 = y, and 8 rows maximum because 8 pixelsearch are done (less rows if some pixelsearch return an error)
- then sort $aResult to get on row 0 the coordinates with the lowest x value

OTOH, you posted a part of the script only and we know nothing about the rest, so impossible to say more. Reason why I suggest some debugs to check if everything is running OK, using _ArrayDisplay, ConsoleWrite etc