Sign in to follow this  
Followers 0
Jeffrey1988

Looping a pixelsearch code

12 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

[center]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.[/center]

Share this post


Link to post
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

Share this post


Link to post
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])

[center]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.[/center]

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

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])


[center]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.[/center]

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

@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

[center]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.[/center]

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

On a side note, why do people insist to ignore the "search" feature of the forums.... i have recently had the same problem and had it resolved...

Edited by backstabbed

tolle indicium

Share this post


Link to post
Share on other sites

thanks allot it works now :)

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

On a side note, why do people insist to ignore the "search" feature of the forums.... i have recently had the same problem and had it resolved...

I did, but couldn't find it with the search option

Edited by Jeffrey1988

Share this post


Link to post
Share on other sites

Oh, then forget i said anything :)


tolle indicium

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