Problems with the image finder

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Taiga
Newbie
Posts: 1
Joined: Fri May 26, 2017 6:03 pm

Problems with the image finder

Post by Taiga » Fri May 26, 2017 6:22 pm

Code: Select all

Let>k=0
Let>db=0
while>k=0

Wait>0.02

FindImagePos>C:\Users\Win\Desktop\kep2.png,SCREEN,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  LClick
  Wait>0.25
  Let>db=db+1
  Message>%db%
  FindImagePos>C:\Users\Win\Desktop\ok.png,SCREEN,0.7,1,XArr,YArr,NumFound,CCOEFF
  If>NumFound>0
  MouseMove>XArr_0,YArr_0
  Wait>0.25
  LClick
  Endif
Endif

Wait>0.02

FindImagePos>C:\Users\Win\Desktop\kep1.bmp,SCREEN,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  LClick
  MouseMove>0,0
  Wait>0.25
  Let>db=db+1
  Message>%db%
  FindImagePos>C:\Users\Win\Desktop\ok.png,SCREEN,0.7,1,XArr,YArr,NumFound,CCOEFF
  If>NumFound>0
  MouseMove>XArr_0,YArr_0
  Wait>0.25
  LClick
  Endif
Endif

Wait>0.05

FindImagePos>C:\Users\Win\Desktop\kep6.png,SCREEN,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  LClick
  MouseMove>0,0
  Wait>0.25
  Let>db=db+1
  Message>%db%
  FindImagePos>C:\Users\Win\Desktop\ok.png,SCREEN,0.7,1,XArr,YArr,NumFound,CCOEFF
  If>NumFound>0
  MouseMove>XArr_0,YArr_0
  Wait>0.25
  LClick
  Endif
Endif

Wait>0.02

FindImagePos>C:\Users\Win\Desktop\kep3.bmp,SCREEN,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  LClick
  MouseMove>0,0
  Wait>0.25
  Let>db=db+1
  Message>%db%
  FindImagePos>C:\Users\Win\Desktop\ok.png,SCREEN,0.7,1,XArr,YArr,NumFound,CCOEFF
  If>NumFound>0
  MouseMove>XArr_0,YArr_0
  Wait>0.25
  LClick
  Endif
Endif

Wait>0.02

FindImagePos>C:\Users\Win\Desktop\kep7.png,SCREEN,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  LClick
  MouseMove>0,0
  Wait>0.25
  Let>db=db+1
  Message>%db%
  FindImagePos>C:\Users\Win\Desktop\ok.png,SCREEN,0.7,1,XArr,YArr,NumFound,CCOEFF
  If>NumFound>0
  MouseMove>XArr_0,YArr_0
  Wait>0.25
  LClick
  Endif
Endif

Wait>0.02

FindImagePos>C:\Users\Win\Desktop\kep5.png,SCREEN,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  LClick
  MouseMove>0,0
  Wait>0.25
  Let>db=db+1
  Message>%db%
  FindImagePos>C:\Users\Win\Desktop\ok.png,SCREEN,0.7,1,XArr,YArr,NumFound,CCOEFF
  If>NumFound>0
  MouseMove>XArr_0,YArr_0
  Wait>0.25
  LClick
  Endif
Endif

Wait>0.02
endwhile
Above you can see the code I am trying to make work.

It works (or at least should work) as the following: random (of 6) images appear on the screen, the macro finds them and clicks on them, at one time only one image is visible, and when the program clicks on them, they disappear and a new picture will appear in another place.

The problem I am experiencing is that sometimes (it is in a mostly random interval of time, but after about ~30-36 found images) the macro double clicks on the image, instead of the simple one time "LClick", as it was supposed to do. That's a big problem, since if you click twice, at the time of the second click the image would've been already disappeared, so I'd lose the game. I used the second "FindImagePos" inside the first "FindImagePos", so it'd write out the current "click" number, and close the pop-up window after 0.25s, so I could check the value. Each time I fail the game, and restart it, at the first click of the restarted program, the click value is (previous game score)+2, instead of (previous game score)+1, so I am pretty sure the game failed, because it double clicked. At each fail the program won't show the last pop-up, it'd just click on the image and the game would almost immediately fail.

What could be the problem?

Thanks,
Taiga

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Problems with the image finder

Post by Marcus Tettmar » Mon May 29, 2017 1:09 pm

Since you only have LClicks in the code I can only assume you are triggering two of these in turn. After each LClick you do another FindImagePos. If that returns a match (maybe false positive) it issues another LClick. From a quick look at the code without being able to debug that is the best answer I can give as to why it appears to double click (click twice).
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

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