Sign in to follow this  
Followers 0
acecase

Allocateing arrays

8 posts in this topic

#1 ·  Posted (edited)

Hey,

I have found several places in the help file that explaine this probably plenty fine for most people but i guess im too slow.

I can't seen to allocate this array.

Dim $vChoords[1][1]

WinActivate("blackend")

Sleep(2000)

WinMove("blackend", "", 0, 0)

Sleep(2000)

$vChoords = PixelSearch(173, 110, 176, 117, 8279893)

Sleep(2000)

If @error = 1

MsgBox(0, "couldn't find the pixel")

Else

MsgBox(0, "choords are:", $vChoords[0] & "," & $vChoords[1])

EndIf

this script is just to help me to find the choords to use for PixelSearch .. i can't use AutoIt's Window Spy because the mouse is messed up in this aplication.

When I run the script i get an error "Subscript used with non-Array variable." and the pointer is at

MsgBox(0, "choords are:", $vChoords[0] & "," & $vChoords[1])

MsgBox(0, "choords are:", $vChoords^

So I assume I'm not Allocateing $vChoords as an array corectly so I have tried it several different ways with no resolve.

Have tried Dim $vChoords[2] as well as trying the script without allocating the variable before useing it .. since autoit seems to create vars as they are defined and does a good job of setting the type.

Edited by acecase

Share this post


Link to post
Share on other sites



Dim $vChoords[1][1]
$c = PixelGetColor(173, 110)
$vChoords = PixelSearch(173, 110, 176, 117, $c)
; ---------------modified code -------------
If @error = 1 then
MsgBox(0, "couldn't find the pixel","")
; ---------------------------------------
Else
MsgBox(0, "choords are:", $vChoords[0] & "," & $vChoords[1])
EndIf

At least under 3.0.81 this is working with the correction which have nothing to do with your problem

I hope that help

Share this post


Link to post
Share on other sites

When you do the Sleep() command after the pixel search that is destroying the contents of @error (it is reset after every function so you must test/save it straight away). Then I guess your IF statement is saying "I found it" and then you are accessing the array - but because your @error test is faulty you will sometimes be accessing an array that doesn't exist...

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

thank you both

jpm..

I have the color code i need it's just that its a (.) so verry small and i can't get the choords useing spy because of a buggy mouse in the aplication.

You're script is useing PixelGetColor to get the color and assumeing the choords I used for my PixelSearch pointed to it wich they don't but instead those choords are just a kinda ruff square around that blue period I am wanting to find.

But thank you for showing how I was messing up the @error var.

I figured it out i think .. I was allocating it rite to start with Dim $var[2] but it isn't giveing any values to the array because it isn't finding it.

Heres another question :whistle:

:iamstupid:

If there are more than one pixel of that color in the defined choords will I get an error or does it return the choords of the first pixel found in that erea or what?

Edited by acecase

Share this post


Link to post
Share on other sites

Don't you think Jon that the error code should not be destroyed if the function does not set it as "Sleep"?

That will avoid a lot of scripter misunderstanding.

Share this post


Link to post
Share on other sites

Thanks guys

I got it now. I thought it should create the veriable i was just trying because the error sounded like it hadn't been created. Turns out the error was telling me that it didn't have any values assined. Turns out it was both that I was breaking the @error check with Sleep like you said and also that my choords where off and it wasn't finding the color within them. I removed the Sleep (which didn't make sense anyway) and widend my search square and it works fine now.

Share this post


Link to post
Share on other sites

It may be easier to learn the rules than remember the exceptions...

Larry,

I don't think that a function not setting an error must me "remember" so it is not an exception.

What is true if an @error is set it can remain until a function want to change it.

The error free programming is easier in my mind.

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