Selecting the closest image match to another image match

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
RedOne684
Newbie
Posts: 1
Joined: Sat Jun 27, 2020 7:13 pm

Selecting the closest image match to another image match

Post by RedOne684 » Sat Jun 27, 2020 7:48 pm

I'm trying to make a script that would pick the closest match to another image in distance. My current script goes for a random pick and ends up failing to do what I'm actually trying to do.

This is what I'm trying to work with:
rsz_screenshot_20200628-025600.png

My current code:

Code: Select all

Repeat>1000

FindImagePos>%BMP_DIR%\image_1.bmp,SCREEN,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  LClick
    Else
      FindImagePos>%BMP_DIR%\image_2.bmp,SCREEN,0.7,1,XArr,YArr,NumFound,CCOEFF
        If>NumFound>0
        MouseMove>XArr_0,YArr_0
          LClick
        Endif
    Endif

wait>2

FindImagePos>%BMP_DIR%\image_3.bmp,SCREEN,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  LClick
Endif

wait>2

FindImagePos>%BMP_DIR%\image_4.bmp,SCREEN,0.6,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  LDblClick
Endif

wait>2

Until>1000
What I want it to do is to click on the match that is closest to the horseman. Any help regarding this issue would be appriciated. Thanks!

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1389
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Selecting the closest image match to another image match

Post by Dorian (MJT support) » Sun Jun 28, 2020 5:59 pm

I'm not sure I understand what you're trying to do, but if your script is finding something it shouldn't (false positives), then maybe try increasing your tolerance from 0.7 to 0.8 or 0.9 and see if it makes a difference.

In the meantime, I think you need help with your Repeat/Until loops. Yours is missing a few elements :

Code: Select all

Let>MyLoop=0
Repeat>MyLoop
  Let>MyLoop=MyLoop+1
  
  //Do something
  Message>Count : %MyLoop%
  Wait>1
  
Until>MyLoop,5
Yes, we have a Custom Scripting Service. Message me or go here

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts