Jump to content

Searching for colour then if found press a button


xyzabc
 Share

Recommended Posts

I tried to do a Programm which repeats searching for an colour and if it finds that colour press a button.

And then search again until it finds it again and press a second button, and then a third after searching again.

And thats the code i tried to do

$pixel = PixelSearch(661,409,1035,444,0xFF1E1E,100,50)
If $pixel <> 1 Then
    send(1)
    sleep(500)

I know that this isnt that hard to do but i dont know how to do this.

If anyone knows how to do this please give me a help or say where i can find it.

Link to comment
Share on other sites

I tried to do a Programm which repeats searching for an colour and if it finds that colour press a button.

And then search again until it finds it again and press a second button, and then a third after searching again.

And thats the code i tried to do

$pixel = PixelSearch(661,409,1035,444,0xFF1E1E,100,50)
If $pixel <> 1 Then
    send(1)
    sleep(500)

I know that this isnt that hard to do but i dont know how to do this.

If anyone knows how to do this please give me a help or say where i can find it.

Here ya go:

While 1
    Sleep(20)
    $pixel = PixelSearch(661,409,1035,444,0xFF1E1E,100,50)
    If @error <> 1 Then
        send(1)
        sleep(500)
    EndIf
WEnd
Link to comment
Share on other sites

First thing i want to say thanks and the second one is

Can i do it for more then 1 button this way?

While 1
    Sleep(20)
    $pixel = PixelSearch(661,409,1035,444,0xFF1E1E,100,50)
    If @error <> 1 Then
        send(1)
        sleep(500)
    EndIf
WEnd
While 1
    Sleep(20)
    $pixel = PixelSearch(661,409,1035,444,0xFF1E1E,100,50)
    If @error <> 1 Then
        send(2)
        sleep(500)
    EndIf
WEnd
While 1
    Sleep(20)
    $pixel = PixelSearch(661,409,1035,444,0xFF1E1E,100,50)
    If @error <> 1 Then
        send(3)
        sleep(500)
    EndIf
WEnd

and third what is @error?

Edited by xyzabc
Link to comment
Share on other sites

Nope that doesn't work.

While 1

Wend

Means that it's going to stay in that chunk of code until you tell it to exit.

I would do it this way:

$Button = 0


While 1
    Sleep(20)
    $pixel = PixelSearch(661,409,1035,444,0xFF1E1E,100,50)
    If @error <> 1 Then
        
        If $Button = 0
            Send(1)
            Sleep(500)
            $Button = 1
        ElseIf $Button =1
            Send(10)
            Sleep(500)
            $Button = 2
        ElseIf $Button =2
            Send(5)
            Sleep(500)
            $Button = 0
        EndIf
        
    EndIf
        
WEnd

That stays in the loop. And everytime a button is found it increases $Button by 1.

@Error is returned by some functions (Like pixelSearch). Help file says:

Success: Returns a two-element array of pixel's coordinates. (Array[0] = x, Array[1] = y)

Failure: Sets @error to 1 if color is not found.

Edited by Szhlopp
Link to comment
Share on other sites

Hmm ok thanks

but doesnt mean this u press button x if colour is not found

an easy yes or no is enough

and a great THANKS

And our script gives an Error

>Running AU3Check (1.54.13.0) from:C:\Programme\AutoIt3

C:\Dokumente und Einstellungen\Julian\Desktop\Versuch3.au3(10,23) : ERROR: multi-line 'If' missing 'Then'.

If $Button = 0

~~~~~~~~~~~~~~~~~~~~~~^

C:\Dokumente und Einstellungen\Julian\Desktop\Versuch3.au3(14,26) : ERROR: syntax error

ElseIf $Button =1

~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Dokumente und Einstellungen\Julian\Desktop\Versuch3.au3 - 2 error(s), 0 warning(s)

Edited by xyzabc
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...