Sign in to follow this  
Followers 0
Justforfun

Array Error Question ?

10 posts in this topic

#1 ·  Posted (edited)

I Have a script and every now and then I get a non-variable array error. Could repeating a pixelesearch like this

Func find()
Do
        $array = PixelSearch(0, 300, 392, 678, 0xff0000, 0, 5); Continues to search for color till its found
    Until @error = 0
    If @error = 0 Then ; verifies @error = 0 then proceeds
      MouseClick( "main", $array[0], $array[1], 2, 10) 
      
EndIf
EndFunc

While 1
find()
Wend

cause the error because I am asking it to wait till @error is 0 then say if it is 0 then proceed to next step?

this is the only thing I could think of that would cause this or do I also need to say

If @error = 1 then
; do nothing
EndIF
because I didn't think it matters if 1 is returned since I am checking for 0.

Any suggestions would be appreciated.

Edited by Justforfun

Share this post


Link to post
Share on other sites



I don't understand this. In the help file there is no mention of @error being set to equal 0. I also don't think you have posted enough code for anyone to see where the error might occur. I am not used to working with PixelSearch, but it appears that you have not declared the variable name of the array. $aiArray = PixelSearch etc... See the example in the help file. Perhaps that's where the problem lies.

Share this post


Link to post
Share on other sites

Okay, so now that you've added a variable name, you need to do something with it. Probably you should declare it using the local keyword (and perhaps outside the function), depending on what you are trying to do. Then you need to test whether @error = 1 (why are you using zero?), and if no error occurs do something either with the coordinates or whatever. If that doesn't work, then post more code so people can help you more easily.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I don't understand this. In the help file there is no mention of @error being set to equal 0. I also don't think you have posted enough code for anyone to see where the error might occur. I am not used to working with PixelSearch, but it appears that you have not declared the variable name of the array. $aiArray = PixelSearch etc... See the example in the help file. Perhaps that's where the problem lies.

I used this to find that @error returns zero when the pixel is found its been modified for this web page

Sleep(3000)
$Pos = Pixelsearch(0, 0, 800, 600, 0x1d3652, 0, 1)
If Not @error Then
MsgBox(0, "Error", @error)
MsgBox(0, " Coords ", " Pixel found at x " & $Pos[0] & " y " & $Pos[1])
EndIf

When it find the pixel it returns 0 if not found it returns 1 I use a script that ask checks for 0 and 1 to perform different functions it just makes it easier for me to use the returns of 0 and 1 for @error

I added to the above script in my first post to make it a full script. Every now and then I get the non-array error can any one tell me what I have done wrong in that script for it to return a error once in awhile.

Edited by Justforfun

Share this post


Link to post
Share on other sites

Okay, I'm a bit tired right now. But before I sleep I'll hazard a guess. The function sets @error to 1 when no matching pixel is found. It does not set it to zero on the next run. Once @error is set to 1 it remains as 1. That's what I think might be happening, though I could be wrong. So after the first time the error is thrown things go wrong. Could that be the problem?

Share this post


Link to post
Share on other sites

Well I see where you might think that but thats what I want it to do is if @error = 1 then it continues to do pixelsearch till @error = 0 so if it looks and does not find the pixel 20 times in a row it just continues to loop till it finds it then @error gets set to 0 and it then does the If Then function. Not sure you understanding how this script runs but I do appreciate the input. Get some rest and thanks for the responses

Share this post


Link to post
Share on other sites

As I didn't want the script to start spamclicking and I wanted the pixelsearch to fail allot, but succeed sometimes. I made a script that I hoped would reproduce the error, but instead runs completely as expected.

Then I tried running your script, using a video as the search area, but that worked as expected too, which leads me to believe the error you are getting might originate somewhere else.

Are you able to reproduce the error with the exact example you posted? If not it would help to see more of the script and a copy/paste of the error message.

Meanwhile you could use

Func find()
    Do
        $array = PixelSearch(0, 300, 392, 678, 0xff0000, 0, 5); Continues to search for color till its found
    Until IsArray($array)
    MouseClick( "main", $array[0], $array[1], 2, 10) 
EndFunc

While 1
    find()
    Sleep(10)
Wend

The non-reproducing reproducer script I used was this:

Local $var = 5

Func find()
    Local $i
    Do
        $i +=1
        Local $r = Hex(Random(0,255,1),2)
        Local $g = Hex(Random(0,255,1),2)
        Local $b = Hex(Random(0,255,1),2)
        Local $rgb = "0x" & $r & $g & $b
        Local $array = PixelSearch(0, 0, @DesktopWidth, @DesktopHeight, $rgb, $var, 5); Continues to search for color till its found
    Until @error = 0
    If @error = 0 Then
        ConsoleWrite("Found color " & $rgb & "±" & $var & " at " & $array[0] & " x " & $array[1] & "on the " & $i & "th try." & @CRLF)
    EndIf
EndFunc

While 1
    find()
    Sleep(10)
Wend

$var gives some control over the successrate, but I never got it to crash.

Share this post


Link to post
Share on other sites

I managed to reproduce the error. But it stopped happening when I modified the code.

find()

Func find()
    Do
    $array = PixelSearch(0, 0, 392, 678, 0xff0000, 0, 5); Continues to search for color till its found
    Until @error = 0
    MsgBox(0, "@error = " & @error, $array[0] &" "& $array[1])
EndFunc

While 1
    find()
Wend

Somewhat confusing. ;)

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Well guys thank you very much for your efforts and replies but the error has been solved it was due to my own neglect to deep search my own script as this took sometime going over it as I was sitting here I was randomly scrolling up and down till I just stoped and there it was right in front of my face a undeclared Pixesearch. I feel like a idot. ;) Thanks again

Oh ya and the script was for icon finding I have about 75,000 icons and there are only about 1,000 that I want to keep thank gosh they are all from the same theme and have the same color border so I can open thumbnail view in my folder and scroll thru the picture and with the script it finds them and moves them to another folder managed to get it done in about 5 minutes once I got the script running would have took hours with the naked eye and click draging to new folder. Yeah autoit!!!

Edited by Justforfun

Share this post


Link to post
Share on other sites

Excellent. I think I'll create something using pixel color functions. I'm thinking along the lines of colour coding text in html. ;)

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