Sign in to follow this  
Followers 0
mjm65

Help with an array

2 posts in this topic

i wrote a code to take a map from the web and find the spaces in it. the $state variable tells me what color the space was. I want to update a 2d array to put the color in as a string. Any help would be appreciated

CODE
#include <array.au3>

#include <GuiConstants.au3>

Global $pic[34][51], $state = 0

Dim $x=0,$i=0,$AnchorX=0, $AnchorY = 0

Sleep(4000)

$coord = PixelSearch(422, 225, 725, 430, 0x998675, 50)

MsgBox(0, "X and Y are:", $coord[0] & "," & $coord[1])

$AnchorX= $coord[0]

$AnchorY = $coord[1]

For $i = 0 To 34 Step 1

For $x= 0 To 51 Step 1

;math to find the pixel

$GetX = ($x * 5) + $AnchorX + 3

$GetY = ($i * 5) + $AnchorY + 3

$state = PixelGetColor($GetX,$GetY)

If $state = 10061429 Then;brown

$state = "1"

ElseIf $state = 1681474 Then ;Green

$state = "2"

ElseIf $state = 16777215 Then ;White

$state = "3"

ElseIf $state = 16711680 Then ;Red

$state = "4"

Else

MsgBox(16, "? ", "ERROR COLOR NOT RECONIZED" + $state)

EndIf

$pic[$i][$x] = $state ; dosen't work

Next

Next

Share this post


Link to post
Share on other sites



Oldest problem in the book :whistle:

Your for loop runs to 34 and 51, but array element [34][51] does not exist. This because you gave your array 34 resp. 51 elements, so their array numbers run from 0 to 33 resp. 50. (This is called 0-based because arrays start at 0 by default.)

I would say, either decrease the for loop by one $i and $x, or increase your array dimensions to 35 and 52 so all will fit...

Google for "0-based" (INclude the quotation marks this time since otherwise google will kill the - :)


Roses are FF0000, violets are 0000FF... All my base are belong to you.

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  
Followers 0