Jump to content
Sign in to follow this  
Paranoia

Array Help

Recommended Posts

Paranoia

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

Share this post


Link to post
Share on other sites
PsaltyDS

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

Share this post


Link to post
Share on other sites
Paranoia

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

Share this post


Link to post
Share on other sites
PsaltyDS

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

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.