OR statement and WaitScreenImage

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
llorenc
Newbie
Posts: 4
Joined: Wed Aug 11, 2021 9:01 am

OR statement and WaitScreenImage

Post by llorenc » Sun Aug 15, 2021 9:33 pm

Hi, I am trying to figure out how to write an OR statement using WaitScreenImage but I wasn't successful.

I want to write a sentence to wait until one of the 2 images appears on the screen.

basically would be like "if this image or this image is recognised... continue "


Can anyone share with me an example of the code that can do this, please?

Thanks!

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

Re: OR statement and WaitScreenImage

Post by Dorian (MJT support) » Mon Aug 16, 2021 9:43 am

Reading between the lines from your previous posts, FindImagePos might be more suitable.

We could use either of these methods :
1. If Image1 is found OR if image 2 is found
2. If image1 isn't found AND image2 isn't found

I've used the latter.

We simply look for image1 and image2, and if they don't exist, we exit. Note that for demonstration purposes I've not included code that "does something" if it is found. The important concept here is the "If".

Code: Select all

//Look for image 1
FindImagePos>%BMP_DIR%\image_1.bmp,WINDOW:*Untitled - Notepad,0,1,XArr,YArr,NumFound1,EXACT

//Look for image 2
FindImagePos>%BMP_DIR%\image_2.bmp,WINDOW:*Untitled - Notepad,0,1,XArr,YArr,NumFound2,EXACT

//If neither exist, exit
If>{(%NumFound1% = 0) AND (%NumFound2% = 0)}
exit
Endif
However, if you want to use WaitScreenImage, we can set a timeout and then get the value of WSI_TIMEDOUT to see if it timed out. This will set a timeout of 3 seconds, look for each image, and exit if neither are found :

Code: Select all

Let>WSI_TIMEOUT=3
WaitScreenImage>%BMP_DIR%\image_1.bmp,0,EXACT
Let>Image1Timeout=WSI_TIMEDOUT

WaitScreenImage>%BMP_DIR%\image_2.bmp,0,EXACT
Let>Image2Timeout=WSI_TIMEDOUT

//If neither exist, exit
If>{(%Image1Timeout% = TRUE) AND (%Image2Timeout% =TRUE)}
exit
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