Choosing second image if first isn't available
Moderators: JRL, Dorian (MJT support)
-
- Newbie
- Posts: 3
- Joined: Sun Jun 09, 2019 3:13 pm
Choosing second image if first isn't available
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.
- Dorian (MJT support)
- Automation Wizard
- Posts: 1415
- Joined: Sun Nov 03, 2002 3:19 am
Re: Choosing second image if first isn't available
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
-
- Newbie
- Posts: 3
- Joined: Sun Jun 09, 2019 3:13 pm
Re: Choosing second image if first isn't available
That worked perfectly thank you so much
- Dorian (MJT support)
- Automation Wizard
- Posts: 1415
- Joined: Sun Nov 03, 2002 3:19 am
Re: Choosing second image if first isn't available
You are very welcome.
Re: Choosing second image if first isn't available
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
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
- Dorian (MJT support)
- Automation Wizard
- Posts: 1415
- Joined: Sun Nov 03, 2002 3:19 am
Re: Choosing second image if first isn't available
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.
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