If true if false

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Flanker
Newbie
Posts: 3
Joined: Tue Oct 11, 2016 8:44 pm

If true if false

Post by Flanker » Tue Oct 11, 2016 9:01 pm

Hello (sorry for my bad english) today i was writing a script (in macro scheduler) for game with image recognition but now i have a problem when i write all good i start trying to make better this script.

I try to do script who can check if image is true or false and make the appropriate functions.

Code: Select all

SetFocus>Vesteris
Wait>5
Label>lol
//Find and Double Right Click Center of 
FindImagePos>%BMP_DIR%\image_11.bmp,WINDOW:Vesteris,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  Wait>0.2
  RClick
  Wait>0.2
  Rclick
Endif

Wait>0.5

//Find and Right Click Center of 
FindImagePos>%BMP_DIR%\image_12.bmp,WINDOW:Vesteris,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  RCLick
Endif

//Find 
FindImagePos>%BMP_DIR%\image_16.bmp,WINDOW:Vesteris,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  MouseMove>XArr_0,YArr_0
Endif 

//Wait for 
WaitScreenImage>%BMP_DIR%\image_14.bmp,0.7,CCOEFF

//Find 
FindImagePos>%BMP_DIR%\image_16.bmp,WINDOW:Vesteris,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
    Goto>true
Endif 




Label>true
//Find and Right Click Center of 
FindImagePos>%BMP_DIR%\image_12.bmp,WINDOW:Vesteris,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  RCLick
  RCLick
  RCLick
  RCLick
Endif



Wait>10
Goto>lol


I mean
If script find image on screen do actions true
http://screenshot.sh/m9lD9LN7UoCvx
like this
http://screenshot.sh/ou0G5NZxjz6p7
If not find, do action false and jump to the next "find image"
like this
http://screenshot.sh/m9lD9LN7UoCvx
and 3 razy,2 razy,1 raz

If somebody can help me i will be grateful

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

Re: If true if false

Post by Marcus Tettmar » Wed Oct 12, 2016 7:42 am

Hi,

Your code will always go to label true. Look carefully at this part of your code:

Code: Select all

If>NumFound>0
    Goto>true
Endif 


Label>true
If NumFound is greater 0, execution will move to the next line "Goto>true" and then jump to Label>true. If NumFound is NOT greater than 0 execution will jump to the Endif, then continue on to "Label>true". So WHATEVER happens you will always go to that label.

You could change it like this:

Code: Select all

If>NumFound>0
  Goto>true
Else
  Goto>false
Endif

Label>true
...
...
Exit>0

Label>false
...
...
Exit>0
Note I have added Exit statements. I'm assuming your script ends after these labels. Without the Exit after the Label>true block, or without something else there, execution is STILL going to flow onto Label>false. Using Gotos and Labels is messy for this reason.

So it would be better just to structure your code like this, WITHOUT using Gotos and Labels:

Code: Select all

If>NumFound>0
  .. 
  .. put your "true" code here
  ..
Else
 ..
 .. put your "false" code here
 ..
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?

Flanker
Newbie
Posts: 3
Joined: Tue Oct 11, 2016 8:44 pm

Re: If true if false

Post by Flanker » Wed Oct 12, 2016 5:32 pm

I did what you said but in game script clicking 14 times not 2/3/4/5 can you tell me what i do wrong ?


Code: Select all

// COMPILE_OPTS|C:\Users\Flanker\Desktop\Fishbot vesteris.exe||CONSOLE=0|INCLUDES=1||RUNTIMES=1|BMPS=1
SetFocus>Vesteris
Wait>5
Label>lol
//Find and Double Right Click Center of
FindImagePos>%BMP_DIR%\image_11.bmp,WINDOW:Vesteris,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  RClick
  Rclick
Endif

Wait>0.5

//Find and Right Click Center of
FindImagePos>%BMP_DIR%\image_12.bmp,WINDOW:Vesteris,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  RCLick
Endif

//Wait for
WaitScreenImage>%BMP_DIR%\image_14.bmp,0.7,CCOEFF

ScreenCapture>1309,27,1757,50,%TEMP_DIR%\screenrect.bmp
//Find and Move Mouse Center of 
FindImagePos>%BMP_DIR%\image_23.bmp,%TEMP_DIR%\screenrect.bmp,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
 //Find and Right Click Center of 
FindImagePos>%BMP_DIR%\image_20.bmp,WINDOW:Vesteris,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  RCLick
  RCLick
  RCLick
Else
Endif
ScreenCapture>1307,24,1754,74,%TEMP_DIR%\screenrect.bmp
//Find and Move Mouse Center of 
FindImagePos>%BMP_DIR%\image_24.bmp,%TEMP_DIR%\screenrect.bmp,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
//Find and Right Click Center of 
FindImagePos>%BMP_DIR%\image_20.bmp,WINDOW:Vesteris,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  RCLick
  RCLick
  RCLick
  RCLick
Else
Endif
ScreenCapture>1304,27,1774,80,%TEMP_DIR%\screenrect.bmp
//Find and Move Mouse Center of 
FindImagePos>%BMP_DIR%\image_25.bmp,%TEMP_DIR%\screenrect.bmp,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
//Find and Right Click Center of 
FindImagePos>%BMP_DIR%\image_20.bmp,WINDOW:Vesteris,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  RCLick
  RCLick
Else
Endif
ScreenCapture>1310,22,1757,76,%TEMP_DIR%\screenrect.bmp
//Find and Move Mouse Center of 
FindImagePos>%BMP_DIR%\image_26.bmp,%TEMP_DIR%\screenrect.bmp,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
//Find and Right Click Center of 
FindImagePos>%BMP_DIR%\image_20.bmp,WINDOW:Vesteris,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  RCLick
  RCLick
  RCLick
  RCLick
  RCLick
endif
Wait>10
Goto>lol









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

Re: If true if false

Post by Marcus Tettmar » Wed Oct 12, 2016 5:36 pm

It is impossible for me to say what is "wrong" since I don't know what logic you are aiming for. You have 18 RClicks so I suppose it could click up to 18 times. Without knowing what your process is, what logic (choices) you want to make, I cannot possibly comment. There is nothing wrong with the code per se, but if it's not doing what you want then you haven't coded it to do what you want, you've coded it to do something else ! :-/
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

Flanker
Newbie
Posts: 3
Joined: Tue Oct 11, 2016 8:44 pm

Re: If true if false

Post by Flanker » Wed Oct 12, 2016 6:39 pm

I mean if script find this image on the screen (in game)
http://screenshot.sh/m1NijV2MFpyGv
Do action true (Rclicking 2 times in this image)
http://screenshot.sh/mMzP2M6Vx5rfR
If not find this image on screen do next script with this image
http://screenshot.sh/mFzuL0D82WSFB
And Rclicking 3 times
And again again again...
Are you understand ?

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

Re: If true if false

Post by Marcus Tettmar » Fri Oct 14, 2016 10:14 am

Ok, based on that your PSEUDOcode is:

Code: Select all

Label>start

FindImagePos>image1 ...
If>Image1Found>0
  FindImagePos>ImageToClickIn
  MouseMove>x,y
  RCLick * 2
Else
  FindImagePos>image2...
  If>Image2Found>0
    MouseMove>x,y
    RCLick * 3
  Endif
Endif

Wait>0.2
Goto>start
So, reading through:

Code: Select all

If image1 is found
  find imagetoclick in and click it twice
else 
  if image 2 is found click it 3 times
end

start all over again 
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

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