joe
Full Member
Posts: 46
|
Post by joe on Jun 9, 2022 5:29:23 GMT
Hello I am trying to make a macro that would do the following: 1. Look at the computer screen for "image A". 2. Then if it finds "image A" it would need to click on the image. 3. But if "image A" is not on the the computer screen then I need the macro to skip ahead to a different macro line.
I think I need to use an "If Then Else" statement but I am not really sure how to do this using the "Add Condition" box. Thanks!
|
|
|
Post by Steve on Jun 9, 2022 9:40:30 GMT
Hi joe Something like this: 1 | IF | DETECT IMAGE | image path C:\Users\steph\Dropbox\Macro\File\pics\capture.bmp::match quick::move mouse yes | IMAGE FOUND | THEN 2 | RUN ACTION | MOUSE CLICK | Left click at %mouse_x% %mouse_y% 1 times with 0 ms delay 3 | IF | ELSE 4 | RUN ACTION | GOTO MACRO LINE | 10 5 | IF | END IF Have a look here www.turnssoft.com/conditions.html#thenelse for more on if-then-else, and here www.turnssoft.com/conditions.html#detectimage for detect image.
|
|
joe
Full Member
Posts: 46
|
Post by joe on Jun 10, 2022 3:41:37 GMT
Thanks Steve!
This works but not in the exact way that I had hoped it would.
Using your example below, if the image in line 1 is detected then line 2 and 4 are executed. And if the image in line 1 is not detected then line 4 is executed. What I am trying to do is if the image in line 1 is detected then only line 2 is executed (and line 4 does not get executed). And if the image in line 1 is not detected then only line 4 is executed. Is this possible?
1 | IF | DETECT IMAGE | image path C:\Users\steph\Dropbox\Macro\File\pics\capture.bmp::match quick::move mouse yes | IMAGE FOUND | THEN
2 | RUN ACTION | MOUSE CLICK | Left click at %mouse_x% %mouse_y% 1 times with 0 ms delay
3 | IF | ELSE
4 | RUN ACTION | GOTO MACRO LINE | 10
5 | IF | END IF
Thanks again!
|
|
|
Post by Steve on Jun 10, 2022 5:11:01 GMT
Using your example below, if the image in line 1 is detected then line 2 and 4 are executed. And if the image in line 1 is not detected then line 4 is executed. What I am trying to do is if the image in line 1 is detected then only line 2 is executed (and line 4 does not get executed). And if the image in line 1 is not detected then only line 4 is executed. Is this possible? Hi joeWhat version of MMM are you using? The syntax for the IF - THEN - ELSE is correct and should only run line 2 if line 1 returns true and should only run line 4 if line 1 returns false. The behavior your describing makes me think your running an older version that isn't compatible with the IF - THEN - ELSE statement.
|
|
joe
Full Member
Posts: 46
|
Post by joe on Jun 12, 2022 22:41:30 GMT
version 8.3.3.0
|
|
|
Post by cyberchipz on Jun 14, 2022 16:07:37 GMT
This works but not in the exact way that I had hoped it would. Using your example below, if the image in line 1 is detected then line 2 and 4 are executed. And if the image in line 1 is not detected then line 4 is executed. What I am trying to do is if the image in line 1 is detected then only line 2 is executed (and line 4 does not get executed). And if the image in line 1 is not detected then only line 4 is executed. Is this possible? 1 | IF | DETECT IMAGE | image path C:\Users\steph\Dropbox\Macro\File\pics\capture.bmp::match quick::move mouse yes | IMAGE FOUND | THEN 2 | RUN ACTION | MOUSE CLICK | Left click at %mouse_x% %mouse_y% 1 times with 0 ms delay 3 | IF | ELSE 4 | RUN ACTION | GOTO MACRO LINE | 10 5 | IF | END IF I know you want an IF THEN ELSE statement; but I would handle it like this.. * | SimpleVersion 1 | IF | DETECT IMAGE | image path C:\Users\steph\Dropbox\Macro\File\pics\capture.bmp::match quick::move mouse yes | IMAGE NOT FOUND | RUN ACTION | GOTO MACRO LINE | NotDetected
* | ImageDetected
2 | RUN ACTION | MOUSE CLICK | Left click at %mouse_x% %mouse_y% 1 times with 0 ms delay * | Or alternately this left click 3 | %mouse_x% | %mouse_y% | 57 | Left Click
9 | RUN ACTION | GOTO MACRO LINE | AfterDetectionCode
* | NotDetected
10| . Insert not detected code here
. .
* | AfterDetectionCode . . .
* | Complex Version 1 | IF | DETECT IMAGE | image path C:\Users\steph\Dropbox\Macro\File\pics\capture.bmp::match quick::move mouse yes | IMAGE NOT FOUND | RUN ACTION | GOTO MACRO LINE | 10
* | ImageDetected
2 | %mouse_x% | %mouse_y% | 57 | Left Click
3 | RUN ACTION | DEFINE BOOLEAN VARIABLE | %FOUNDCAPTURE%::TRUE
* | I only added line above if I need to know later if the image had been clicked or detected.
4 | RUN ACTION | DEFINE INTEGER VARIABLE | %CAPTUREX%::%mouse_x%
5 | RUN ACTION | DEFINE BOOLEAN VARIABLE | %CAPTUREY%::%mouse_y%
* | I added the above line if I need to click it later; with the boolean TRUE I know this is the detected location
. Additional Code if needed.
.
.
* | I only added lines above if I need to know where to click later.
9 | RUN ACTION | GOTO MACRO LINE | AfterDetectionCode
* | NotDetected
10| 987 | RUN ACTION | DEFINE BOOLEAN VARIABLE | %FOUNDCAPTURE%::FALSE
* | I only added line above if I need to know later if the image had NOT been clicked or detected.
11 | Insert Code Here for Not Detected
3 | RUN ACTION | DEFINE INTEGER VARIABLE | %CAPTUREX%::456
3 | RUN ACTION | DEFINE BOOLEAN VARIABLE | %CAPTUREY%::789
* | I only added lines above if I need to know where to click if I didn't find the image (default determined manually: ie: if the image changes or moved.. * | With the manually entered location, if the image is not detected, I can still click it if I need to and with boolean FALSE I know it's my own values it's using.
. Code
.
* | AfterDetectionCode
Thanks again!
|
|
joe
Full Member
Posts: 46
|
Post by joe on Jun 18, 2022 20:09:07 GMT
Thank you CyberChipz, I think that worked!
|
|