Jump to content

Do not repeat pixel search?


Recommended Posts

I have a script...

HotKeySet("{F11}", "_MyExit")



While 1
    $coord = PixelSearch( 28, 59, 28, 59, 0x6B7539, 10 )
    If IsArray($coord) Then                                          ;If pixel color is 0x6B7539
        MouseClick("left", 28, 59, 1, 1)                                ;then move to mouse coordinates (28, 59)
        Sleep(5000)                                                  ;Wait 5 seconds
        SomeFunction()                                                ;Start Some Function
    EndIf
WEnd

Func SomeFunction()
    $coord = PixelSearch( 874, 6, 874, 6, 0x63656B, 10 )
    If IsArray($coord) Then                                          ;If pixel color is 0x63656B
        MouseClick("left", 874, 6, 1, 1)                              ;then move to mouse coordinates (28, 59)
        Sleep(5000)                                                  ;Wait 5 seconds
        SomeOtherFunction()                                          ;Start Some Function
    EndIf
EndFunc;==>SomeFunction

Func SomeOtherFunction()
EndFunc;==>SomeOtherFunction 


Func _MyExit()
    Exit
EndFunc

Now, after it sees the color 0x6B7539, it will click the desired coordiantesm then after it sees 0x63656B, it will go there. But if it sees the first color, 0x6B7539 again in that coordinate, it will click there again which I don't want, I want it to end after it finds the color. And I want all pixel searches fter that to start after the previous pixel was found

Link to comment
Share on other sites

Check to see if your pixelcheck is failing in SomeFunction(). If it is failing it will miss the call to the next function and go back to the original function when it hits the end of SomeFunction().

On a side note: I would recommend structuring this script differently. If you constantly call a new function from within a function without ever letting a function complete and return, you will eventually overload the stack and get a recursion error.

Nomad.

Link to comment
Share on other sites

  • Moderators

Check to see if your pixelcheck is failing in SomeFunction(). If it is failing it will miss the call to the next function and go back to the original function when it hits the end of SomeFunction().

On a side note: I would recommend structuring this script differently. If you constantly call a new function from within a function without ever letting a function complete and return, you will eventually overload the stack and get a recursion error.

Nomad.

I'm not quite sure that's where he was heading with the question, I'm assuming that each function looks for a color, I'm a tad confused myself, so might try this to see if it works:
HotKeySet("{F11}", "_MyExit")
Global $0x6B7539 = 0, $0x63656B = 0


While 1
    $coord = PixelSearch( 28, 59, 28, 59, 0x6B7539, 10 )
    If IsArray($coord) And Not $0x6B7539 Then                               ;If pixel color is 0x6B7539
        $0x6B7539 = 1
        MouseClick("left", 28, 59, 1, 1)                                ;then move to mouse coordinates (28, 59)
        Sleep(5000)                                                     ;Wait 5 seconds
        SomeFunction()                                                  ;Start Some Function
    ElseIf IsArray($coord) Then
        SomeFunction()
    EndIf
WEnd

Func SomeFunction()
    $coord = PixelSearch( 874, 6, 874, 6, 0x63656B, 10 )
    If IsArray($coord) And $0x6B7539 And Not $0x6B7539 Then            ;If pixel color is 0x63656B
        $0x63656B = 1
        MouseClick("left", 874, 6, 1, 1)                              ;then move to mouse coordinates (28, 59)
        Sleep(5000)                                                     ;Wait 5 seconds
        SomeOtherFunction()                                             ;Start Some Function
    ElseIf IsArray($coord) And $0x6B7539 Then
        SomeOtherFunction()
    EndIf
EndFunc;==>SomeFunction

Func SomeOtherFunction()
EndFunc;==>SomeOtherFunction


Func _MyExit()
    Exit
EndFunc
Personally, the more I look at this, I think you should just do return values 0/1 and put them all in functions so you know where/what to search.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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