Sign in to follow this  
Followers 0
Schoening

Multi PixelSearch

25 posts in this topic

#1 ·  Posted (edited)

I am trying to do Multiple Pixelsearch in Diffrent Areas of the Screen, and use the values of those Searches to Calculate which one is closest to the Y axe of the Screen.

I have tried to work with the FastFind.dll but it did not do it for me, and i found it highly unstable.

But stuff like that is Not the end of the World and instead challenges me to think about new ways of solving my Problem ! :)

(Warning!) Please read my Whole Topic before Answering since some of the stuff i type is for explanatory purpose and might give you a wrong idea what i am asking about if taken out of the Context.

Here is a Simple PixelSearch i am Doing:

Local $color = PixelSearch(540,0,740,512, 0xFF0302,20)

Select
Case Not @error              ;If PixelSearch Was SuccessFull
MouseMove ($color[0],$color[1],10)

No Problem Here..

Now what i want to do is split the screen into separate areas and search those areas with pixelsearch.

That should work by using some Operators on the Arrays of Pixelsearch .. lets try it out

The Idea is that the program finds out which of the 3 PixelSearch Array[1] is Closest to 512, and i want the programt to do this even if 1-2 pixelsearch give @error.. if all 3 return @error, i want it to "msgbox" me about that.

(To make it Easier for the moment i do all PixelSearch on the Left side of my Screen.)

But i have Failed! Here are some example scripts of my Trials:

HotKeySet("{ESC}", "End")

While 1
Sleep(1000)
Sleep(10)
$pixelsearch1 = PixelSearch(100,300,200,512,0x0000ff,10)
Sleep(10)
$pixelsearch2 = PixelSearch(250,300,400,512,0xfa0000,10)
Sleep(10)
$pixelsearch3 = PixelSearch(500,300,600,512,0x00ff00,10)
Sleep(10)
Select
Case Not @error
MsgBox(0,"Message","Pixel Found!")
    Case @error
  MsgBox(0,"Message","Could not Find Color")
Case Else
MsgBox(0,"Error","Error")
EndSelect
WEnd
Func End()
Exit
Endfunc

This First Script allways returns Not @error i am using 255 Blue 255 Red and 255 Green.. and only allowing a shade Variation of 10. But even if i have Notepad Hide the Whole Screen in White.. i still get the Not @error message.

And even if it was working.. It is not returning any Usefull information other than that Not @error, and i dont even know if that is for 1 PixelSearch or them all !

When i change the MsgBox to this:

HotKeySet("{ESC}", "End")

While 1
Sleep(1000)
Sleep(10)
$pixelsearch1 = PixelSearch(100,300,200,512,0x0000ff,10)
Sleep(10)
$pixelsearch2 = PixelSearch(250,300,400,512,0xfa0000,10)
Sleep(10)
$pixelsearch3 = PixelSearch(500,300,600,512,0x00ff00,10)
Sleep(10)
Select
Case Not @error
MsgBox(0,"Message",$pixelsearch1 & @CRLF & $pixelsearch2 & @CRLF &  $pixelsearch3)
    Case @error
  MsgBox(0,"Message","Could not Find Color")
Case Else
MsgBox(0,"Error","Error")
EndSelect
WEnd
Func End()
Exit
Endfunc

The the MsgBox is Empty. No Wonder ! PixelSearch is supposed to return a 2 element Array.

Since my script is supposed to Calculate which PixelSearch is Closest to my Location (Center of Y on my Screen) I tried to use the Array[1] since that is the one for the Y axe.

Select
Case Not @error
MsgBox(0,"Message","Pixel Found!")
    Select
Case $pixelsearch1[1] > $pixelsearch2[1] And $pixelsearch1[1] > $pixelsearch3
  MsgBox (0,"Message",$pixelsearch1[1])
Case $pixelsearch2[1] > $pixelsearch1[1] And $pixelsearch2[1] > $pixelsearch3
        MsgBox (0,"Message",$pixelsearch2[1])
Case $pixelsearch3[1] > $pixelsearch1[1] And $pixelsearch3[1] > $pixelsearch2
        MsgBox (0,"Message",$pixelsearch3[1])
case Else
  MsgBox(0,"Error","Array > Operator Select Case Failed")
EndSelect

It gives me the MsgBox "Pixel Found!" so It is Not Error. But then it Gives me the MsgBox from Case Else.

I don't get the Problem of Case Else when i only run 2 Arrays.

Case $pixelsearch1[1] > $pixelsearch2[1]

So i suppose i could run a very long Select Case where i keep comparing 2 Arrays with each other.. If there is no other way?

The far bigger problem, are the @error returns from all PixelSearch, if just 1 Pixelsearch returns @error the script Fails and gives me: Subscript used with non-Array variable.:

That is ofcouse because the @error is not a Array ! But could i perhaps assign it a Array?

It does not Seem like i am able to run Multiple PixelSearch in one Function?

Can i perhaps run several pixelsearch functions and use some Return to calculate ? Or assign the @errors of Diffrent Pixelsearch Different Values before i do the Select Case for @Error?

-------------------------------------------------------------------------------------------------------

I hope this gives you some idea of what i want to achieve.

But let's wrap it up:

I need Multiple PixelSearch in Diffrent Areas of the Screen.

I need to calculate which of the PixelSearch is closest to the Center of the Y axe, even if one, more, or all, PixelSearch Return @error.

If PixelSearch Returns @error, perhaps assign it a value. Since it it using the Y axe, and 512 is greatest number, and i am trying to get as close to 512 as possible. i could assign @error with 0, so another Not @error will be greater.

When all PixelSearch show @error i need to be informed about that aswell to take action.

Edited by Schoening

Share this post


Link to post
Share on other sites



well last time i checked sleep() func dont return error?!!


TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

If i could assign @error with a Array like [0] i could perhaps work with it.

Share this post


Link to post
Share on other sites

well last time i checked sleep() func dont return error?!!

Yeah.. dunno about the Sleep() Sleep is Healthy

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

maby something like this :D

While 1
    Sleep(1000)
    $pixelsearch1 = PixelSearch(100,300,200,512,0x0000ff,10)
    _errorcheck(@error)
    $pixelsearch2 = PixelSearch(250,300,400,512,0xfa0000,10)
    _errorcheck(@error)
    $pixelsearch3 = PixelSearch(500,300,600,512,0x00ff00,10)
    _errorcheck(@error)
WEnd
Func End()
    Exit
Endfunc
Func _errorcheck($errcheck)
    Select
        Case Not $errcheck
            MsgBox(0,"Message","Pixel Found!")
        Case $errcheck
      MsgBox(0,"Message","Could not Find Color")
    EndSelect
    Sleep(10)
EndFunc

nothe that @error check last line in script, in your case it checked sleep ;) hope this fixez it :)

you can try IsArray($varname) but @error shud work fine it this case :)

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

Ty :);) ..

Uhm... and thx for the Heads Up.. i dint realize that Sleep() could harm in any way lol !

Perhaps you can explain me why Sleep is doing it wrong? Last line ?

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

because @error check if sleep have any error, if you needed to check do pixel have error you need to pun @error on next line to pixelsearch not on next line to sleep :)

c the diffrance?

$pixelsearch1 = PixelSearch(100,300,200,512,0x0000ff,10)
Sleep(10)
If @error; check is sleep returned error
 
$pixelsearch1 = PixelSearch(100,300,200,512,0x0000ff,10)
If @error; check is PixelSearch returned error
Sleep(10)
Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

haha ! Now that is very very good to know :)

Share this post


Link to post
Share on other sites

Hi,

to elaborate on the subject, every funtion call automaticly resets @error and @extended so you will need to check for those values directly after the function call.

If you have a function that needs to precede the check, Sleep in this case, you can wrap it in a simple user function to pass on the values of @error and @extended as parameters.

Example:

SetError(1, 1) ; set @error and @extended
ConsoleWrite("@error = " & @error & " @extended = " & @extended & @CRLF) ; output: @error = 1 @extended = 1

SetError(1, 1)
Sleep(10) ; this will reset @error and @extended
ConsoleWrite("@error = " & @error & " @extended = " & @extended & @CRLF) ; output: @error = 0 @extended = 0

SetError(1, 1)
_Foo() ; this will also reset @error and @extended, even when the function is empty
ConsoleWrite("@error = " & @error & " @extended = " & @extended & @CRLF) ; output: @error = 0 @extended = 0

SetError(1, 1)
_Sleep(10) ; this will preserve @error and @extended
ConsoleWrite("@error = " & @error & " @extended = " & @extended & @CRLF) ; output: @error = 1 @extended = 1

Func _Sleep($ms, $error = @error, $extended = @extended)
    Sleep($ms)
    SetError($error, $extended) ; set @error and @extended
EndFunc

Func _Foo() ; empty function
EndFunc

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Hi,

to elaborate on the subject, every funtion call automaticly resets @error and @extended so you will need to check for those values directly after the function call.

Doesnt that mean i can't do more that one PixelSearch ? Or just that i have to assign the Errors right after being found

Edited by Schoening

Share this post


Link to post
Share on other sites

You could just save the value of @error for later use. For example:

$pixelsearch1 = PixelSearch(100,300,200,512,0x0000ff,10)
$pixelSearch1Error = @error
Sleep(10)
$pixelsearch2 = PixelSearch(250,300,400,512,0xfa0000,10)
$pixelSearch2Error = @error
Sleep(10)
$pixelsearch3 = PixelSearch(500,300,600,512,0x00ff00,10)
$pixelSearch3Error = @error
Sleep(10)

or you could use an array to store it.

and then you can just read that data later on.

:)

Share this post


Link to post
Share on other sites

You could just save the value of @error for later use. For example:

$pixelsearch1 = PixelSearch(100,300,200,512,0x0000ff,10)
$pixelSearch1Error = @error
Sleep(10)
$pixelsearch2 = PixelSearch(250,300,400,512,0xfa0000,10)
$pixelSearch2Error = @error
Sleep(10)
$pixelsearch3 = PixelSearch(500,300,600,512,0x00ff00,10)
$pixelSearch3Error = @error
Sleep(10)

or you could use an array to store it.

and then you can just read that data later on.

:)

Ty ;)

To all of you Really ! What to do without you xD

Share this post


Link to post
Share on other sites

You can do more then one PixelSearch but you indeed have to check @error right after calling it.

Something like showed will work just fine.

$pixelsearch1 = PixelSearch(100, 300, 200, 512, 0x0000ff, 10)
If @error Then ConsoleWrite("!> Could not find color!" & @CRLF)
Sleep(10)

$pixelsearch2 = PixelSearch(250, 300, 400, 512, 0xfa0000, 10)
If @error Then ConsoleWrite("!> Could not find color!" & @CRLF)
Sleep(10)

$pixelsearch3 = PixelSearch(500, 300, 600, 512, 0x00ff00, 10)
If @error Then ConsoleWrite("!> Could not find color!" & @CRLF)
Sleep(10)

Share this post


Link to post
Share on other sites

I will check it out :) I hope the Store @error array will work for me

Share this post


Link to post
Share on other sites

So far so good. But i now get the Problem that i need to check more possibilities. It has to check if Both A and B (and C)are NOT @Error

Global $pixelSearchError1 = @error
Global $pixelSearchError2 = @error
Global $pixelSearchError3 = @error
While 1
Sleep(1000)
Sleep(10)
$pixelsearch1 = PixelSearch(100,300,200,512,0x0000ff,10)
$pixelSearchError1 = @error
$pixelsearch2 = PixelSearch(250,310,400,512,0xfa0000,10)
$pixelSearchError2 = @error
$pixelsearch3 = PixelSearch(500,300,600,512,0x00ff00,10)
$pixelSearchError3 = @error
Sleep(1000)
Call("_errorcheck")WEnd
Func _errorcheck()
    Select
        Case Not $pixelSearchError1 And Not $pixelsearch2
            MsgBox(0,"Message","Pixel Found!")
        Case $pixelSearchError1
      MsgBox(0,"Message","Could not Find Color")
    EndSelect
    Sleep(10)
EndFunc

It only checks $pixelSearchError1 for @error and Not $pixelSearchError2

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

My only idea atm is to do multiple Select Cases inside each other for every @error or Not @error.

But it would be much much faster if i would combine @error A and @error B etc. on one line.

Edited by Schoening

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

Ok Here is What i Came Up With

Global $pixelSearchError1 = @error
Global $pixelSearchError2 = @error
Global $pixelSearchError3 = @error
While 1
Sleep(1000)
Sleep(10)
$pixelsearch1 = PixelSearch(100,300,200,512,0x0000ff,10) ;Blue
$pixelSearchError1 = @error
$pixelsearch2 = PixelSearch(250,310,400,512,0xfa0000,10) ;Red
$pixelSearchError2 = @error
$pixelsearch3 = PixelSearch(500,300,600,512,0x00ff00,10) ;Green
$pixelSearchError3 = @error
Sleep(1000)
Call("_errorcheck")
WEnd
Func _errorcheck()
    Select                                                        ;Check for Blue Color, Then Proceed.
        Case Not $pixelSearchError1                              ;Found Blue
            MsgBox(0,"Message","Blue Pixel Found!")
   Select                                                 ;Blue Found.  Now check for Red
    Case Not $pixelsearch2                            ;Found Blue and Red
     MsgBox(0,"Message","Blue and Red Pixel Found!")
     Select                                       ;Blue and Red found. Now check for Green
      Case Not $pixelsearch3                      ;Found Blue, Red and Green
        MsgBox(0,"Message","Blue,Red and Green Pixel Found!")
       Case $pixelsearch3                             ;Blue, Red  But not Green
        MsgBox(0,"Message","Found Blue, Red But Not Green")
      EndSelect
     Case $pixelsearch2          ;Blue Found, But Not Red
      MsgBox(0,"Message","Blue Found, But Not Red")
         Select                                       ;Blue and Red found. Now check for Green
          Case Not $pixelsearch3                      ;Found Blue, Green But not Red
        MsgBox(0,"Message","Found Blue, Green But Not Red")
       Case $pixelsearch3                           ;Blue, But not Red or Green
        MsgBox(0,"Message","Could only Find Blue")
      EndSelect
  Case $pixelSearchError1                                    ;Blue Not Found
      MsgBox(0,"Message","Blue Pixel Not Found")
            Select                                                ;Blue Not Found.  Now check for Red
    Case Not $pixelsearch2                            ;Found Red, But not Blue
     MsgBox(0,"Message","Found Red, But not Blue")
     Select                                       ;Found Red, But not Blue Now check for Green
      Case Not $pixelsearch3                      ;Red and Green, but not Blue
        MsgBox(0,"Message","Red,Green But not Blue")
       Case $pixelsearch3                             ;Red, But not  Blue or Green
        MsgBox(0,"Message","Could only Find Red")
      EndSelect
     Case $pixelsearch2          ;Could not find Blue or Red
      MsgBox(0,"Message","Could not Find Blue and Red")
         Select                                       ;Blue and Red Not found. Now check for Green
          Case Not $pixelsearch3                      ;Only found Green
        MsgBox(0,"Message","Only found Green")
       Case $pixelsearch3                           ;Blue, But not Red or Green
        MsgBox(0,"Message","No Color was found")
      EndSelect

     EndSelect
     EndSelect
EndSelect
    Sleep(10)
EndFunc

But it is SloooooooooooooooOOOOoW !

I Might be able to boost the Speed with FindFast.Dll But i would Prefer to Compare @error in one Line instead

Edit: Not Slow. Just Not Running The Cases Atm.

I stay with my Question, is there a Way to Compare Multiple @Error Variables in one Line?

Edited by Schoening

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

Yes, i have to Correct.. It is not Slow.. It is just Not Running any Case When Blue is Not There, Thus Not showing Any Message

Edited by Schoening

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

you could save the errors on an array, and then run a loop to make sure that all three pixelsearch functions worked as planned.

$pixelsearch1 = PixelSearch(100,300,200,512,0x0000ff,10)
$pixelSearchError[0] = @error
Sleep(10)
$pixelsearch2 = PixelSearch(250,300,400,512,0xfa0000,10)
$pixelSearchError[1] = @error
Sleep(10)
$pixelsearch3 = PixelSearch(500,300,600,512,0x00ff00,10)
$pixelSearchError[2] = @error
Sleep(10)
For $tempCounter = 0 To 2 Step 1
   If $pixelSearchError[$tempCounter] = 1 Then  $errorExists = True
Next

Though it depends on how you want this to run, you could have all the pixelsearching in a function, and then when you are testing for the errors, if an error exists, have it run the pixelsearching function again. That way, it will keep looping until none of the pixelsearching throws an error.

So something like

For $tempCounter = 0 To 2 Step 1
   If $pixelSearchError[$tempCounter] = 1 Then pixelSearch()
Next

:)

Edited by mischieftoo

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