Jump to content

Allocateing arrays


acecase
 Share

Recommended Posts

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
Link to comment
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

Link to comment
Share on other sites

  • Administrators

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...

Link to comment
Share on other sites

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
Link to comment
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.

Link to comment
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.

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...