Jump to content

Looping a pixelsearch code


Recommended Posts

hi there,

I made a script for a game that searches for a red dot on a radar, if there isn't a red dot on the given area then the code starts to press on the right keyboard button until it sees a red dot

below you can see the code I made for this

(NOTE: the message box in the code is only for testing if the code actually did work)

Opt("ColorMode",1)
  $aPixelSearch = PixelSearch(943,658,950,716,0x303AF8,0)
  If @error Then
    send ( "{right}" )
    autoitsetoption ( "sendkeydowndelay", 100 )
  else
    MsgBox(0, "X and Y are:", $aPixelSearch[0] & "," & $aPixelSearch[1])
  EndIf
oÝ÷ ÚØ^¦ºé¡£¯z¸¬¶­"wvÚ+z¶Ø^¦,^Ç­È_ºw-ÛyÆ®±ì!zzkzË"
âmç(-¢,q©çx-æ«y¤ájÝý³r!ÈZ¶¡×­¢Ø^¢wzZ0jëh×6
Opt("ColorMode",1)
$aPixelSearch = PixelSearch(943,658,950,716,0x303AF8,0)
If @error Then
    send ( "{right}" )
    autoitsetoption ( "sendkeydowndelay", 100 )
      $aPixelSearch = PixelSearch(943,658,950,716,0x303AF8,0)
      If @error Then
         send ( "{right}" )
         autoitsetoption ( "sendkeydowndelay", 100 )
          $aPixelSearch = PixelSearch(943,658,950,716,0x303AF8,0)
          If @error Then
             send ( "{right}" )
             autoitsetoption ( "sendkeydowndelay", 100 )
               $aPixelSearch = PixelSearch(943,658,950,716,0x303AF8,0)
               If @error Then
                 send ( "{right}" )
                 autoitsetoption ( "sendkeydowndelay", 100 )
                  $aPixelSearch = PixelSearch(943,658,950,716,0x303AF8,0)
                  If @error Then
                     send ( "{right}" )
                     autoitsetoption ( "sendkeydowndelay", 100 )
                      $aPixelSearch = PixelSearch(943,658,950,716,0x303AF8,0)
                      If @error Then
                         send ( "{right}" )
                         autoitsetoption ( "sendkeydowndelay", 100 )
                      else
                         MsgBox(0, "X and Y are:", $aPixelSearch[0] & "," & $aPixelSearch[1])
                      EndIf
                  else
                     MsgBox(0, "X and Y are:", $aPixelSearch[0] & "," & $aPixelSearch[1])
                  EndIf
               else
                 MsgBox(0, "X and Y are:", $aPixelSearch[0] & "," & $aPixelSearch[1])
               EndIf
          else
             MsgBox(0, "X and Y are:", $aPixelSearch[0] & "," & $aPixelSearch[1])
          EndIf
      else
         MsgBox(0, "X and Y are:", $aPixelSearch[0] & "," & $aPixelSearch[1])
      EndIf
else
    MsgBox(0, "X and Y are:", $aPixelSearch[0] & "," & $aPixelSearch[1])
EndIf

My question:

Is it possible to loop this code somehow , that even when the code presses the right button it still does a pixelsearch?

Best regards,

Jeffrey

Link to comment
Share on other sites

  • Moderators

Opt('SendKeyDownDelay', 100)
Opt('ColorMode', 1)
$aPixelSearch = PixelSearch(943,658,950,716,0x303AF8)
While @error
    $aPixelSearch = PixelSearch(943,658,950,716,0x303AF8)
    Send('{RIGHT}')
    Sleep(10)
WEnd
MsgBox(0, "X and Y are:", $aPixelSearch[0] & "," & $aPixelSearch[1])

Edit:!

Edited by SmOke_N

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

Opt('SendKeyDownDelay', 100)
Opt('ColorMode', 1)
$aPixelSearch = PixelSearch(943,658,950,716,0x303AF8)
While @error
    $aPixelSearch = PixelSearch(943,658,950,716,0x303AF8)
    Send('{RIGHT}')
    Sleep(10)
WEnd
MsgBox(0, "X and Y are:", $aPixelSearch[0] & "," & $aPixelSearch[1])

Edit:!

Thanks for the fast reply, but it doesn't work

it gives me a error

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

MsgBox(0, "X and Y are:", $aPixelSearch^ERROR

Error: Subscript used with non-Array variable.

I tried to edit the script but I keep getting the same error

Link to comment
Share on other sites

  • Moderators

Try this then (It's an all nighter for me) :)

While Not @error
    $aPixelSearch = PixelSearch(943,658,950,716,0x303AF8)
    Send('{RIGHT}')
    Sleep(10)
WEnd
MsgBox(0, "X and Y are:", $aPixelSearch[0] & "," & $aPixelSearch[1])

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

Try this then (It's an all nighter for me) :)

While Not @error
    $aPixelSearch = PixelSearch(943,658,950,716,0x303AF8)
    Send('{RIGHT}')
    Sleep(10)
WEnd
MsgBox(0, "X and Y are:", $aPixelSearch[0] & "," & $aPixelSearch[1])
It's still giving the same error somehow , I've been trying to figure out how to get it work but it just wont. I tried Do and Until functions but nothing seems to work.

Perhaps I should do it on a totally different way?

The script only has to

search for a red dot on a given area,if on that area isn't a red dot then the script needs to keep pressing right until the red dot appears on the given area.

I hope someone can come up with perhaps a totally new script?

Link to comment
Share on other sites

  • Moderators

Opt('SendKeyDownDelay', 100)
Opt('ColorMode', 1)
$aPixelSearch = PixelSearch(943,658,950,716,0x303AF8)
If @error Then
     While @error
         $aPixelSearch = PixelSearch(943,658,950,716,0x303AF8)
        Send('{RIGHT}')
        Sleep(10)
    WEnd
EndIf
MsgBox(0, "X and Y are:", $aPixelSearch[0] & "," & $aPixelSearch[1])

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

@error is cleared by the send

Opt('SendKeyDownDelay', 100)
Opt('ColorMode', 1)
$aPixelSearch = PixelSearch(943, 658, 950, 716, 0x303AF8)
If @error Then
    Do
        Send('{RIGHT}')
        Sleep(10)
        $aPixelSearch = PixelSearch(943, 658, 950, 716, 0x303AF8)
    Until Not @error
EndIf
MsgBox(0, "X and Y are:", $aPixelSearch[0] & "," & $aPixelSearch[1])

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

  • Moderators
@error is cleared by the send
Opt('SendKeyDownDelay', 100)
Opt('ColorMode', 1)
$aPixelSearch = PixelSearch(943, 658, 950, 716, 0x303AF8)
If @error Then
    Do
        Send('{RIGHT}')
        Sleep(10)
        $aPixelSearch = PixelSearch(943, 658, 950, 716, 0x303AF8)
    Until Not @error
EndIf
MsgBox(0, "X and Y are:", $aPixelSearch[0] & "," & $aPixelSearch[1])oÝ÷ Ûú®¢×k+¦N­ßÛ0«Hë_¢¹Þ½êízËb
+$x-«'q«Gb´hmºË®±ç«®ß¢·îËb¢{-«kzÛ«
ëk+"³r"G©¶Ç+{§+n¥ú+ë"ÇjÊÇ^rV«zl¯j¸nW¬Ü(ºWaj÷yéí+ºÚ"µÍÜ
    ÌÎNÔÙ[Ù^QÝÛ[^IÌÎNËL
BÜ
    ÌÎNÐÛÛÜ[ÙIÌÎNËJBØØ[ ÌÍØT^[ÙXÚ    ÌÍØT^[ÙXÚH^[ÙXÚ
MË
NML
ÌMÌÐQ
BÙ[
    ÌÎNÞÔQÒIÌÎNÊBÛY
L
B[[Ð^J ÌÍØT^[ÙXÚ
BÙÐÞ
    ][ÝÖ[HN][ÝË ÌÍØT^[ÙXÚÌH   [È ][ÝË  ][ÝÈ  [È ÌÍØT^[ÙXÚÌWJ
Edited by SmOke_N

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