Choosing second image if first isn't available

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Crumpledpapr
Newbie
Posts: 3
Joined: Sun Jun 09, 2019 3:13 pm

Choosing second image if first isn't available

Post by Crumpledpapr » Mon Jun 10, 2019 4:41 am

Hi I'm having issues trying to figure out how to create a either or scenario with image recognition. Basically I'm running a loop waiting for one of two images to come up, finding either one and clicking and moving on with the script. Any help would be appreciated.

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

Re: Choosing second image if first isn't available

Post by Dorian (MJT support) » Mon Jun 10, 2019 10:05 pm

How about something like this?

Code: Select all

//Wait until either of two images appears by using a While Loop

Let>AnImageWasFound=FALSE
While>AnImageWasFound=FALSE
  //Here we use two FindImagePos statements - one for each image
  FindImagePos>%BMP_DIR%\image_2.bmp,SCREEN,0.7,1,XArr,YArr,NumFound1,CCOEFF
  FindImagePos>%BMP_DIR%\image_3.bmp,SCREEN,0.7,1,XArr,YArr,NumFound2,CCOEFF
  //Now we see if one or other was found
  If>NumFound1>0
    //First Image Was Found - do something
  
    .. your  code here - or run a subroutine or goto a label or something
    
    //set AnImageWasFound flag to end the While loop
    Let>AnImageWasFound=TRUE
  Else
    If>NumFound2>0
      //Second Image Was Found - do something else
      .. your  code here - or run a subroutine or goto a label or something
      //set AnImageWasFound flag to end the While loop
    Let>AnImageWasFound=TRUE
    Endif
  Endif
EndWhile
//When we get here one of the images was found and acted on
Yes, we have a Custom Scripting Service. Message me or go here

Crumpledpapr
Newbie
Posts: 3
Joined: Sun Jun 09, 2019 3:13 pm

Re: Choosing second image if first isn't available

Post by Crumpledpapr » Tue Jun 11, 2019 3:20 am

That worked perfectly thank you so much

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

Re: Choosing second image if first isn't available

Post by Dorian (MJT support) » Thu Jun 13, 2019 2:36 pm

You are very welcome.
Yes, we have a Custom Scripting Service. Message me or go here

Frizze
Newbie
Posts: 5
Joined: Mon Sep 09, 2019 7:48 am

Re: Choosing second image if first isn't available

Post by Frizze » Tue Sep 10, 2019 7:58 pm

Hi, i think i can use this topic for my problem

I can´t get my code working as i imagine.

I want to search for ~15 different Images, some images are shown 2 times, some 7 times and some only once. And not all are active at the same time.

so i imagine:
1. If -> one of the images is there -> then klick on it and perform the same action every time.

2. If -> one of the images is NOT there -> search for next image and return to 1

3. if -> None of the Images is found -> End


I am all new to coding, i tryed 3 Days, single lines of Code are working, image find is working, but i do not understand "IF " "else" "loop" and this things ( LET... for what do i need that ) , and the Help File is absulut not helpful for me. I don´t get it. the Examples are very short and not good explained.

Please someone help. sorry for bad english

sorry for complaining

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

Re: Choosing second image if first isn't available

Post by Dorian (MJT support) » Thu Sep 19, 2019 9:30 am

hi,

If I understand correctly, this does what you need. It looks for and clicks Image1 in a loop. If Image1 is not found, it will look for and click Image2, then go back to the Image1 loop. If neither are found, the script will Exit.

Code: Select all

Label>FirstImage
FindImagePos>%BMP_DIR%\image_1.bmp,SCREEN,0.7,1,XArr,YArr,Num1Found,CCOEFF
If>Num1Found>0
  MouseMove>XArr_0,YArr_0
  LClick
  Wait>1
  Goto>FirstImage
Else
  FindImagePos>%BMP_DIR%\image_2.bmp,SCREEN,0.7,1,XArr,YArr,Num2Found,CCOEFF
  If>Num2Found>0
    MouseMove>XArr_0,YArr_0
    LClick
    Wait>1
    Goto>FirstImage
    Else
    Exit
  Endif
Endif

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