Jump to content

Array Help


Recommended Posts

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.

$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

When you declare $Res, give it sufficient elements for when you reference it later with $i and $j:

Global $Res[10][10]

:shocked:

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

  • 1 month later...

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 by Paranoia
Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

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