Makalele Posted August 5, 2009 Share Posted August 5, 2009 Hi there! I need to make function, which finds block of pixels (the same color ofc). I wrote simple function, it works, but sometimes can't escape from loop So i need your help with fixing this function or the new one, more professional - but - must be fast >_< Here it is: expandcollapse popupFunc FindBlock($nColor,$X1=0, $Y1=0, $X2=800, $Y2=490) ;min. size 4x4 Dim $temparray[4], $i, $a, $b, $BlockW, $BlockH $temparray[0]=0 $temparray[1]=0 $temparray[2]=0 $temparray[3]=0 $IsBlock = False $a=$X1 $b=$Y1 $BlockW=0 $BlockH=0 While $BlockH=0 $Check = PixelSearch($a, $b, $X2, $Y2, $nColor) If @error Then Return $temparray EndIf $b=$Check[1] $BlockW=0 $BlockH=0 $j = $Check[1] For $i = $Check[0] To $X2 If PixelGetColor($i,$j) <> $nColor Then If ($i - $Check[0] < 4) Then $a=$i ExitLoop Else $BlockW = $i - $Check[0] ExitLoop EndIf EndIf Next If $BlockW > 0 Then For $i = $Check[1] To $Y2 If PixelGetColor($Check[0] + $BlockW - 1,$i) <> $nColor Then If ($i - $Check[1] < 4) Then ExitLoop Else $BlockH = $i - $Check[1] ExitLoop EndIf EndIf Next EndIf If $BlockH > 0 Then For $i = $Check[0] To $Check[0] + $BlockW - 1 If PixelGetColor($i,$Check[1]+$BlockH-1) <> $nColor Then $BlockW = 0 $BlockH = 0 ExitLoop EndIf Next IF $BlockH > 0 Then For $i = $Check[1] To $Check[1] + $BlockH - 1 If PixelGetColor($Check[0]+$BlockW-1,$i) <> $nColor Then $BlockW = 0 $BlockH = 0 ExitLoop EndIf Next EndIf EndIf WEnd $temparray[0]=$Check[0] $temparray[1]=$Check[1] $temparray[2]=$BlockW $temparray[3]=$BlockH Return $temparray EndFunc it's not so good function so i prefer if someone has better than mine Link to comment Share on other sites More sharing options...
Makalele Posted August 5, 2009 Author Share Posted August 5, 2009 Now i think this function is useless, need NEW function - finding block >_ Link to comment Share on other sites More sharing options...
Makalele Posted August 6, 2009 Author Share Posted August 6, 2009 Still need help >_ Link to comment Share on other sites More sharing options...
Makalele Posted August 6, 2009 Author Share Posted August 6, 2009 Hmm, i think i did it finally:expandcollapse popupFunc FindBlock($nColor,$X1,$Y1,$X2,$Y2) Dim $temparray[2],$a,$b,$i,$j,$IsBlock $temparray[0]=0 $temparray[1]=0 $a=$X1 $b=$Y1 While 1 $Check = PixelSearch($a,$b,$X2,$Y2,$nColor) If @error Then Return $temparray EndIf $a=$Check[0] $b=$Check[1] $IsBlock = True For $j=$b To $b+4 For $i=$a To $a+4 If PixelGetColor($i,$j) <> $nColor Then $IsBlock = False $a+=($i-$a) ExitLoop 2 EndIf Next Next If $IsBlock Then $temparray[0]=$a $temparray[1]=$b Return $temparray EndIf WEnd EndFuncBut.. If i use this again (with a little sleep, the same screen of course) it returns 0... i really don't know why it happens.. Anyone knows? Link to comment Share on other sites More sharing options...
Makalele Posted August 6, 2009 Author Share Posted August 6, 2009 (edited) I finally figured out, what's wrong. It's not about the function, it's just because of 32bit depth, pixels are changing all time, even i see the same.. So i guess i have to back to 16bits Topic can be closed now. Edit: It's not certainly caused of 32bits, but of 32bits in game which i play (or so i'm creating a bot >_< ) Edited August 6, 2009 by Makalele Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now