how do u use the label, goto, and if commands?

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
nani555
Newbie
Posts: 2
Joined: Thu Jan 08, 2009 6:12 pm

how do u use the label, goto, and if commands?

Post by nani555 » Thu Jan 08, 2009 6:16 pm

im a noob :cry: and a beginner at macro scheduler

i want to know how to use the label, IF, and goto commands

first i want the macro to find an image on the screen
IF it finds it, then i want it to continue with the macro....
IF it doesnt find it i need it to do something else.
can anyone help me format this using the label, IF, and goto commands?

thankyou!
any help would immensly be appreciated!

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Jan 08, 2009 7:05 pm

Using a script mostly found in the help for FindImagePos>.

Code: Select all

GetScreenRes>X,Y
ScreenCapture>0,0,X,Y,d:\screen.bmp

///assuming "d:\today_button.bmp" is an actual file on your computer.
FindImagePos>d:\today_button.bmp,d:\screen.bmp,0,1,X,Y,NumFound

If>NumFound>0
  Goto>ImageFound
Else
  Goto>ImageNotFound
Endif

Label>ImageFound
  ///Do Something
Goto>Next

Label>ImageNotFound
  ///Do Something Else

Label>Next

nani555
Newbie
Posts: 2
Joined: Thu Jan 08, 2009 6:12 pm

Post by nani555 » Thu Jan 08, 2009 7:22 pm

but what if i used waitscreenimage?

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Jan 08, 2009 10:47 pm

but what if i used waitscreenimage?
From Help for WaitScreenImage>
*******************************************************
WaitScreenImage>BitmapFile[,Color_Tolerance]

Waits until the image in BitmapFile is found on the screen.
Returns the number of occurrences found on the screen in the WSI_RESULT variable.

Optionally, a Color tolerance value can be specified. The default is 0 (no tolerance). If color_tolerance is zero the pixel colors must match exactly. color_tolerance can be set to a value between 0 and 255. If larger than zero the red, green and blue values of the pixels in bitmap_to_scan are checked to see if they are within the tolerance specified (color value + or - color_tolerance). Smaller values match less and larger values match more.

The system variable WSI_TIMEOUT can be used to set the number of seconds after which this command should timeout. If set to zero (the default) the timeout will not occur and the command will continue indefinitely. If WSI_TIMEOUT is used, WSI_TIMEDOUT will indicate whether or not the command ended successfully. If it timed out WSI_TIMEDOUT will be set to TRUE otherwise, if the image was found within the time out period it will be set to FALSE.
*******************************************************

Therefore, Using WaitScreenImage uses logic something like this:

Code: Select all

Let>WSI_TIMEOUT=5
///assuming "d:\today_button.bmp" is an actual file on your computer.
WaitScreenImage>d:\today_button.bmp

If>WSI_TIMEDOUT=FALSE
  Goto>ImageFound
Else
  Goto>ImageNotFound
Endif

Label>ImageFound
///Do Something
Goto>Next

Label>ImageNotFound
///Do Something Else

Label>Next

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

Post by Marcus Tettmar » Fri Jan 09, 2009 9:06 am

I could be stating the obvious but you do not need to use Goto/Label. My preference is as follows:

Code: Select all

Let>WSI_TIMEOUT=5
///assuming "d:\today_button.bmp" is an actual file on your computer.
WaitScreenImage>d:\today_button.bmp

If>WSI_TIMEDOUT=FALSE
  //Image Found - do something
  MessageModal>Found It!
Else
  //Image not found - do something else
  MessageModal>Not Found!
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?

minchia
Newbie
Posts: 14
Joined: Tue Apr 28, 2009 8:33 am

Post by minchia » Wed Apr 29, 2009 2:23 am

hmm, this might be gold for me.

bennyn
Newbie
Posts: 9
Joined: Fri Nov 19, 2010 1:00 pm
Contact:

Post by bennyn » Fri Mar 04, 2011 10:54 am

I run the following code:

Code: Select all

Let>WSI_TIMEOUT=5
Let>imageNeedle={"\\homer\existent_file.bmp"}

WaitScreenImage>%imageNeedle%,0
If>WSI_TIMEDOUT=FALSE
  MessageModal>Found It!
Else
  MessageModal>Not Found!
Endif
If imageNeedle exists then the script tells me "Found it!" but if imageNeedle is set to "\\homer\this_file_does_not_exist.bmp" then it tells me "Found it!" too. What's wrong with it?

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