Nested If Statement Workaround [Help pls]

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
natherox
Newbie
Posts: 2
Joined: Wed Jan 24, 2018 2:29 am

Nested If Statement Workaround [Help pls]

Post by natherox » Wed Jan 24, 2018 2:48 am

Hello!
I am new to this program and so far enjoying it, but I need help when I need to ask a else if statement.
Basically, I'm searching for the first image. If the first image is not there "do this". If the first image is there, search for the second image. If the second image is not there "do this" and if it is there "do this".

Here is my current code:

Code: Select all

FindImagePos>%BMP_DIR%\image_3.bmp,SCREEN,0.7,1,XArr,YArr,NumFound1,CCOEFF
FindImagePos>%BMP_DIR%\image_19.bmp,SCREEN,0.7,1,XArr,YArr,NumFound2,CCOEFF

IfNot>NumFound1>0
  HoldKey>s,100,0,1
  else
  HoldKey>space,100,0,1
  Wait 2
    If>NumFound2>0      
      HoldKey>d,100,0,1
      Wait 2
      HoldKey>space,100,0,1
      else
      Wait 4
      HoldKey>space,200,0,1
    Endif
Endif
Currently the code does not work as supposed to. It mainly has trouble when it goes about searching for the second image.
I know the code is poorly optimized and there is a much better way to do this. I'm a very poor coder so with that in mind, any help is very much appreciated. Thanks! :D

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

Re: Nested If Statement Workaround [Help pls]

Post by Marcus Tettmar » Wed Jan 24, 2018 9:05 am

The way your code is structured it searches for BOTH images BEFORE your logic. I also wouldn't use IfNot as that becomes more confusing. If image 1 is not found NumFound1 will be zero, so just check for that. Larger than zero would mean it WAS found.

I THINK you want something like this:

Code: Select all

FindImagePos>%BMP_DIR%\image_3.bmp,SCREEN,0.7,1,XArr,YArr,NumFound1,CCOEFF
If>NumFound1=0
  //image 1 was NOT found, so do this:
  HoldKey>s,100,0,1
Else
  //image 1 WAS found, so do this:
  HoldKey>space,100,0,1
  Wait 2
  //are you waiting long enough here for image 2 to show up?
  //Search for second image ...
  FindImagePos>%BMP_DIR%\image_19.bmp,SCREEN,0.7,1,XArr,YArr,NumFound2,CCOEFF
  If>NumFound2>0 
    //second image WAS found, so do this:     
    HoldKey>d,100,0,1
    Wait 2
    HoldKey>space,100,0,1
  Else
     //second image was NOT found, so do this:
     Wait 4
     HoldKey>space,200,0,1
  Endif
Endif
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

natherox
Newbie
Posts: 2
Joined: Wed Jan 24, 2018 2:29 am

Re: Nested If Statement Workaround [Help pls]

Post by natherox » Thu Jan 25, 2018 4:26 am

This works perfectly, thanks so much for the help!

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