Jump to content

How to ImageSearchArea with 2 images. Code inside


Recommended Posts

Hello . 

It's been quite some time since i've used AutoIt and im banging my head on the wall trying to figure this out. I have two images that will appear in a specific area on my screen (ImageSearchArea) However they will not appear at the same time. I am trying to have my script look for the first and if it isnt there it looks for the next, if thats not there the script repeats. I'm really unsure on how to implement the arrays into the ImageSearchArea functionality.

take a look at what i've come up with please.

 

#include <ImageSearch2015.au3>
 
$x1 = 1690
$y1 = 113
$x2 = 1752
$y2 = 735
 
$returnX = 0
$returnY = 0
 
$picture = "UpDoot.png"
 
$result = _ImageSearchArea($picture, 1, $x1, $y1, $x2, $y2, $returnX, $returnY, 100, 0)
if $result = 1 Then
   ;MouseMove ($returnX, $returnY, 10)
   Tooltip("UpDoot Found")
   SLeep(1000)
 
Else
   Tooltip("Error!")
   SLeep(1000)
EndIf
Link to post
Share on other sites

Here the basic of a loop :

Local $result, $returnX, $returnY

While True
  Sleep (500)
  $result = _ImageSearchArea($picture, 1, 1690, 113, 1752, 735, $returnX, $returnY, 100, 0)
  If $result = 1 Then
    ConsoleWrite ("first found" & @CRLF)
    ; do your stuff here
    ContinueLoop
  EndIf
  $result = _ImageSearchArea($picture, 1, 200, 300, 400, 500, $returnX, $returnY, 100, 0)
  If $result = 1 Then
    ConsoleWrite ("second found" & @CRLF)
    ; do your stuff here
  EndIf
WEnd

 

Link to post
Share on other sites
14 minutes ago, Nine said:

Here the basic of a loop :

Local $result, $returnX, $returnY

While True
  Sleep (500)
  $result = _ImageSearchArea($picture, 1, 1690, 113, 1752, 735, $returnX, $returnY, 100, 0)
  If $result = 1 Then
    ConsoleWrite ("first found" & @CRLF)
    ; do your stuff here
    ContinueLoop
  EndIf
  $result = _ImageSearchArea($picture, 1, 200, 300, 400, 500, $returnX, $returnY, 100, 0)
  If $result = 1 Then
    ConsoleWrite ("second found" & @CRLF)
    ; do your stuff here
  EndIf
WEnd

 

Hey. works perfectly. THank you

Link to post
Share on other sites

is it possible to have a variable add +1 when image search is found

THen when 2nd image is found it takes that variable and performs an operation X amount of times?

Then resetting the variable back to 0

Link to post
Share on other sites

Yes everything is possible...  But I am curious to know what is the application you are trying to automate ?  What is the operation you want to perform X amount of times ?  There are better ways to automate application than using ImageSearch.  So could you help me understand what you are trying to achieve first ?

Link to post
Share on other sites
6 minutes ago, Nine said:

Yes everything is possible...  But I am curious to know what is the application you are trying to automate ?  What is the operation you want to perform X amount of times ?  There are better ways to automate application than using ImageSearch.  So could you help me understand what you are trying to achieve first ?

sure. THanks for the help so far. so I am playing with paper money in think or swim and trying to have it watch a trend i wrote where it indicates buy or sell. im having it check every 10 seconds for an indicator. sometimes it will buy more than it sells which isnt locking in my fake profits !  so i figured if i could keep a variable count every time the buy indicator hits - when that sell indicator pops up it will sell times X to bring my shares down to 0

Link to post
Share on other sites

Could you show me a screenshot of this application, it would help me figuring out the flow of your automation. Thanks.

Link to post
Share on other sites
6 minutes ago, Nine said:

Could you show me a screenshot of this application, it would help me figuring out the flow of your automation. Thanks.

 

The red and green arrows is what the imagesearch is looking for

 

image.png.f8702b51ba72a3e42c612220ef7c36ac.png

Link to post
Share on other sites
5 minutes ago, Nine said:

Isn't that some sort of a game ?  Looks very much like it I must say.  Right ?

no its called think or swim. definitely not a game. it measures volume in a stock. im doing the paper money version for testing.    modding games is not supported here i believe? so i definitely would not be trying to break the rules.

Edited by Teckx
Link to post
Share on other sites

Ok.  I went to TDAmeritrade, look like your screen shot. So, lets go back to your request.

1 hour ago, Teckx said:

is it possible to have a variable add +1 when image search is found

THen when 2nd image is found it takes that variable and performs an operation X amount of times?

Then resetting the variable back to 0

You will have to declare a variable before the loop.  Then increase that variable in first found.  And when in second found execute your operation the variable time and set it to 0 after.  Try putting something together and come back with you attempt if it fails.

 

Link to post
Share on other sites
2 hours ago, Nine said:

Ok.  I went to TDAmeritrade, look like your screen shot. So, lets go back to your request.

You will have to declare a variable before the loop.  Then increase that variable in first found.  And when in second found execute your operation the variable time and set it to 0 after.  Try putting something together and come back with you attempt if it fails.

 

 

Something like this?

N will be the value i'll be using

 

Local $result, $returnX, $returnY

$r= 0
$n= 0

While True
  Sleep (500)
  $result = _ImageSearchArea($picture, 1, 1690, 113, 1752, 735, $returnX, $returnY, 100, 0)
  If $result = 1 Then
    ConsoleWrite ("first found" & @CRLF)
    $r= ($r + 1)
       ContinueLoop
  EndIf
  $result = _ImageSearchArea($picture, 1, 200, 300, 400, 500, $returnX, $returnY, 100, 0)
  If $result = 1 Then
    ConsoleWrite ("second found" & @CRLF)
    $n = $r * Number("100")
    $r= 0
  EndIf
WEnd
Edited by Teckx
Link to post
Share on other sites

Please do not quote everything I said, just use the reply box at the bottom of the thread.   It makes the thread cumbersome for nothing. 

Also use this tool when you post code.  It is easier for us to read it.

As for your code, you are getting close :).  Did you try to run it from Scite ?  The error I believe is self-explanatory.

Also you can use += operator like this :

$r += 1 ; instead of $r = $r + 1 (parenthesis are useless in this situration)

Look help file for more details.

Link to post
Share on other sites

Hello all

having trouble getting this conditional IF to work

its ignoring the & $r >= 1

 

 

$result = _ImageSearchArea($picture1, 1, 1759, 122, 1831, 735, $returnX, $returnY, 100, 0)
  If $result = 1 & $r >= 1 Then
    ;ConsoleWrite ("second found" & @CRLF)
MouseClick("left",1293,379,1,0)
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...