Sign in to follow this  
Followers 0
Wallfire

Array Me

5 posts in this topic

im having trouble understanding the help file on arrays. could someone give me the low-down on arrays? like how to declare, how to define, when and where i can use them, etc...

i would like to grab points and store the X,Y locations in one array instead of having 2 varaibles to keep track of.

here is an example of when i would like to use an array:

GetPixelColor($ArrayPoint)

where $ArrayPoint is a (X,Y) cordinate.


:cheer: awww...wheres the chick?

Share this post


Link to post
Share on other sites



Hope this helps:

Dim $myCoord[2]

$myCoord[0] = 479
$myCoord[1] = 639

$color = GetPixelColor($myCoord)

MsgBox("4096","", "The color at my coordinate is " & $color)

Func GetPixelColor($point)
   If Not IsArray($point) Then
      MsgBox(4096,"Error", "GetPixelColor was not passed an array!")
   Else
      Return PixelGetColor ( $point[0] , $point[1] )
   EndIf
EndFunc

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

ok, great. thanks. i think i get it now, its pretty simple. i dont know why i couldnt grasp the concept before.

here is what i made, almost excatly like yours...just not with that array checking step. thats smart.

Dim $MyArray[2]

$MyArray[0]=10
$MyArray[1]=20


$color=PixelGetColor($MyArray[0],$MyArray[1])
MsgBox(4096,"Arraystuff:",$color,4)
Edited by Wallfire

:cheer: awww...wheres the chick?

Share this post


Link to post
Share on other sites

One other thing, and why to really use arrays, is that they can be called in loops.

Dim $MyArray[2]
$MyArray[0]="Blue"
$MyArray[1]="Red"

for $i=0 to 1
msgbox(1,"Color",$MyArray[$i])
next

You can also get more complex very easy:

Dim $MyArray[2][2]
$MyArray[0][0]="Blue"
$MyArray[1][0]="Red"
$MyArray[0][1]="Ocean"
$MyArray[1][1]="Stopsign"


for $i=0 to 1
msgbox(1,$MyArray[$i][0],$MyArray[$i][1])
next

a nice quick way to populate an array is using StringSplit:

$MyArray=StringSplit("Blue|Red","|"); create array
; this creates a 3 element array with the first element having the amount of elements besides itself. In this case $MyArray[0]=2
for $i=1 to $MyArray[0]
msgbox(1,"Color",$MyArray[$i])
next

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

hmm...yes, i can see where things can get complex with arrays.

one questiong tho:

when you did this:

$MyArray[0][0]="Blue"
$MyArray[1][0]="Red"
$MyArray[0][1]="Ocean"
$MyArray[1][1]="Stopsign"

is that 'populating?' a 2X2 array?

my only other programing language that i know is MATLAB and it doesnt use arrays, but matrices. that look like:

Matrix=[1 2;3 4]

that would make a matrix that looks like:

1 2
3 4

so when you do:

Dim $MyArray[2][2]

that is making a 2X2 empty array, (or 'matrix' in my thinking...)

what is the syntax on that? would Dim $MyArrat[3] [2] make a 3X2 or a 2X3?

and is this a 3X2?:

1 2 3
4 5 6

thanks again for explaining what you have so far, i tried teaching myself C a few months ago but got lost when it started talking about ararys and other stuff...im just not used to dealing with them.


:cheer: awww...wheres the chick?

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