Sign in to follow this  
Followers 0
Esam

Array and @error problems

10 posts in this topic

Hi, I am writing my first AutoIt script and I'm having a problem doing a pixelsearch. The application is loading and although the title bar shows up, the screen has not yet loaded fully. So I do a pixelsearch on a section that has a known color in a do loop until it is loaded. However, I am having two problems. I have pasted the offending code below along with the questions. Let me know what you think.

Dim $loopCount = 0, $search_tries = 10

Do ;Waiting for screen to showup

$coord = PixelSearch(450,140,470,160,0xFFFFBD)

$loopcount = $loopcount + 1

sleep(1000)

Until Not @error OR $loopcount = $search_tries

If @error Then

MsgBox(48, "Unable to find init pixel! Aborting..."

Exit

EndIf

MouseClick ("left", $coord[0], $coord[1], 1,10)

(1) Originally my sleep was too short and I ended my do loop based on $loopcount reaching 10. However, I didn't get the "Unable to find pixel" message. Why is @error not set by the time I check the if statement? It must have been or else Not @error would have ended my do loop. Is there some time the @error flag is reset that I do not understand?

(2) I increased sleep to 1000 as shown above. The do loop now ends prior to reaching $loopcount of 10. However, I get an error about the MouseClick telling me that I am trying to treat a non array as an array. Shows me something like $coord^ERROR or something. According to the PixelSearch documentation, PixelSearch returns an array and the example shows it accessing $coord in the same way I have done. What am I doing wrong? I attempted to explicitly declare $coord as well with a line of Dim $coord[2] but that had the same effect.

Thanks in advance,

Esam

Share this post


Link to post
Share on other sites



Hi, I am writing my first AutoIt script and I'm having a problem doing a pixelsearch. The application is loading and although the title bar shows up, the screen has not yet loaded fully. So I do a pixelsearch on a section that has a known color in a do loop until it is loaded. However, I am having two problems. I have pasted the offending code below along with the questions. Let me know what you think.

Dim $loopCount = 0, $search_tries = 10

Do ;Waiting for screen to showup

$coord = PixelSearch(450,140,470,160,0xFFFFBD)

$loopcount = $loopcount + 1

sleep(1000)

Until Not @error OR $loopcount = $search_tries

If @error Then

MsgBox(48, "Unable to find init pixel! Aborting..."

Exit

EndIf

MouseClick ("left", $coord[0], $coord[1], 1,10)

(1) Originally my sleep was too short and I ended my do loop based on $loopcount reaching 10. However, I didn't get the "Unable to find pixel" message. Why is @error not set by the time I check the if statement? It must have been or else Not @error would have ended my do loop. Is there some time the @error flag is reset that I do not understand?

(2) I increased sleep to 1000 as shown above. The do loop now ends prior to reaching $loopcount of 10. However, I get an error about the MouseClick telling me that I am trying to treat a non array as an array. Shows me something like $coord^ERROR or something. According to the PixelSearch documentation, PixelSearch returns an array and the example shows it accessing $coord in the same way I have done. What am I doing wrong? I attempted to explicitly declare $coord as well with a line of Dim $coord[2] but that had the same effect.

Thanks in advance,

Esam

For your message box, you didn't specify a title - which is why you're getting the wrong number of args error..

Change to..

MsgBox(48, "", "Unable to find init pixel! Aborting...")

And your $coord variable is not an array.


Ben

Share this post


Link to post
Share on other sites

For your message box, you didn't specify a title - which is why you're getting the wrong number of args error..

Change to..

MsgBox(48, "", "Unable to find init pixel! Aborting...")

And your $coord variable is not an array.

Ok. I fixed the message box. However, that was not an error I was getting. I still have the same problem. Message box never gets called even though @error should be set. And as for my $coord variable... I have copied the EXACT example from the PixelSearch documentation below...

; Find a pure red pixel in the range 0,0-20,300

$coord = PixelSearch( 0, 0, 20, 300, 0xFF0000 )

If Not @error Then

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

EndIf

It seems to me what I am doing is exactly the same...

Thank you,

Esam

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Ok. I fixed the message box. However, that was not an error I was getting. I still have the same problem. Message box never gets called even though @error should be set. And as for my $coord variable... I have copied the EXACT example from the PixelSearch documentation below...

; Find a pure red pixel in the range 0,0-20,300

$coord = PixelSearch( 0, 0, 20, 300, 0xFF0000 )

If Not @error Then

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

EndIf

It seems to me what I am doing is exactly the same...

Thank you,

Esam

I think that example is no good. If you change "If Not @error" to "If @error" (or have that colored pixel in the search location) then you'll produce the same problem you're having with that sample code.

EDIT: I just looked at pixel search - i've never used it. Says it returns an array.. Hmm...

Edited by bboysza

Ben

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

For your message box, you didn't specify a title - which is why you're getting the wrong number of args error..

Change to..

MsgBox(48, "", "Unable to find init pixel! Aborting...")

And your $coord variable is not an array.

I added a shade-variation and it worked.

Dim $loopCount = 0, $search_tries = 10

Do;Waiting for screen to showup
$coord = PixelSearch(450,140,470,160,0xFFFFBD, 30)
$loopcount = $loopcount + 1
sleep(1000)
Until Not @error OR $loopcount = $search_tries

If @error Then
MsgBox(48, "", "Unable to find init pixel! Aborting...")
Exit
EndIf

MouseClick ("left", $coord[0], $coord[1], 1,10)

So $coord never gets populated when there's no match - hence the var treated as array error.

Edited by bboysza

Ben

Share this post


Link to post
Share on other sites

Ok I guess my biggest question then is... WHY doesn't my if statement properly detect the error flag is set? Is the flag cleared immediately after being checked?

Share this post


Link to post
Share on other sites

Ok I guess my biggest question then is... WHY doesn't my if statement properly detect the error flag is set? Is the flag cleared immediately after being checked?

I think it is set, it's just cleared after the next function [or function prior to @error] runs successfully.

Ben

Share this post


Link to post
Share on other sites

I am not sure of the workings of it, but the @error is reset with every new function call. Just calling the Until statement I think may reset it. Not too positive what is resetting it in your script, but it is being reset reguardless.

Some code that may help... (work around)

Dim $loopCount = 0, $search_tries = 10, $d_error

While 1;Waiting for screen to showup
   $coord = PixelSearch(450,140,470,160,0xFFFFBD)
   
   $loopcount = $loopcount + 1

   Sleep(1000)

   If $loopcount = $search_tries Then
      $d_error = "true"
      ExitLoop
   EndIf
WEnd

If $d_error = "true" Then
   MsgBox(48, "Unable to find init pixel!", "Aborting...")
   Exit
EndIf

MouseClick ("left", $coord[0], $coord[1], 1,10)

The above code is untested, but I am pretty sure it will work. It is from your original example.

Also including your code blocks in the [ code ]code here[ / code ] tags helps out alot. Makes it easier to read. As does indenting the text.

May want to try the SciTE editor for AutoIt. It is very handy. Helps with code and indentation.

JS


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
Share on other sites

I do have indentation in my program.. For some reason my tabs didn't display in my message, however.

Share this post


Link to post
Share on other sites

I do have indentation in my program.. For some reason my tabs didn't display in my message, however.

Ah must only do the indentation when in the code block. B)

JS


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

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