Paranoia Posted April 20, 2007 Share Posted April 20, 2007 I'm trying to make a program to find the center of an object which is a single color. I have never used arrays before and i am unsure how to write them. This is what I have so far. expandcollapse popup$WinName = $BallColor = $BallShadeVar = $PixelSkip = ;Auto Global $Coord Global $Res $Vertical = 0 $Horizontal = 0 $AvgNum = 0 $WinSize = WinGetClientSize($WinName) $WidthInc = ($WinSize[0] / 10) $HeightInc = ($WinSize[1] / 10) Opt("CaretCoordMode", 0) For $i = 1 to 10 step 1 For $j = 1 to 10 step 1 SetError(0) $L = ($WidthInc * ($i - 1)) $T = ($HeightInc * ($j - 1)) $R = ($WidthInc * $i) $B = ($HeightInc * $j) $Coord = PixelSearch( $L, $T, $R, $B, $BallColor, $BallShadeVar, $PixelSkip) If @error Then $Res[$i][$j] = 0 Else $Res[$i][$j] = 1 EndIf Next Next For $i = 1 to 10 step 1 For $j = 1 to 10 Step 1 $Horizontal = ($Horizontal + ($Res[$i][$j] * $i)) $AvgNum = $AvgNum + $Res[$i][$j] Next Next $iCenter = ($Horizontal / $AvgNum) $AvgNum = 0 For $i = 1 to 10 step 1 For $j = 1 to 10 Step 1 $Vertical = ($Vertical + ($Res[$i][$j] * $j)) $AvgNum = $AvgNum + $Res[$i][$j] Next Next $jCenter = ($Vertical / $AvgNum) If your wondering I'm building myself a little robot to chase a ball around. Thanks, Paranoia Link to comment Share on other sites More sharing options...
PsaltyDS Posted April 20, 2007 Share Posted April 20, 2007 When you declare $Res, give it sufficient elements for when you reference it later with $i and $j: Global $Res[10][10] Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Paranoia Posted May 26, 2007 Author Share Posted May 26, 2007 (edited) Thanks! Edit: I'm now having trouble with... $Coord[$i][$j] = PixelSearch( $L, $T, $R, $B, $BallColor, $BallShadeVar, $PixelSkip) I think it's because PixelSearch is an array, but I don't know how to fix this. also, sorry for the extremely late reply, I had forgotten I had posted this and I had not needed to use this script until now. :"> Edited May 26, 2007 by Paranoia Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 26, 2007 Share Posted May 26, 2007 You can, actually, store and array in an array element, but that is complicated, confusing, and best avoided. (If you want an esoteric exercise: you have to read it 'out' of the parent array to another to use it). Just give yourself another array to catch the return value: Dim $CoordRet[2] ; $CoordRet[0] = x, [1] = y $CoordRet = PixelSearch( $L, $T, $R, $B, $BallColor, $BallShadeVar, $PixelSkip) Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Paranoia Posted May 26, 2007 Author Share Posted May 26, 2007 That'll work! Thanks again Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 26, 2007 Share Posted May 26, 2007 That'll work! Thanks again You're welcome. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law 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