What's wrong with Else If

Advanced Macro Recorder/Editor.

Moderator: Pulover

User avatar
Muhammadi
Posts: 36
Joined: 27 May 2021, 20:00

What's wrong with Else If

Post by Muhammadi » 31 May 2021, 12:17

Hi,

The problem is with my incorrect usage of Else If.
Please let me know where I made the mistake.

Thanks,
Muhammadi

Code: Select all

CoordMode, Pixel, Window
ImageSearch, FoundX, FoundY, 334, 456, 416, 491, C:\Users\KILLERWHALE\AppData\Roaming\MacroCreator\Screenshots\Screen_20210531073118.png
Sleep, 1111
If (ErrorLevel)
{
    CoordMode, Pixel, Window
    ImageSearch, FoundX, FoundY, 330, 459, 419, 510, C:\Users\KILLERWHALE\AppData\Roaming\MacroCreator\Screenshots\Screen_20210531165725.png
    CenterImgSrchCoords("C:\Users\KILLERWHALE\AppData\Roaming\MacroCreator\Screenshots\Screen_20210531165725.png", FoundX, FoundY)
    Sleep, 1111
}
Else If (ErrorLevel)
{
    MsgBox, 0, , A
}
Else
{
    MsgBox, 0, , B
}
[Mod edit: [code][/code] tags added.]
User avatar
Muhammadi
Posts: 36
Joined: 27 May 2021, 20:00

Re: What's wrong with Else If

Post by Muhammadi » 31 May 2021, 12:48

When I remove Else If and one of the Image Searches, everything works fine.
But with Else If it doesn't give any result, it doesn't give any message.

I incorrectly used Else If.
Please let me know where I made the mistake.

Can someone write a similar simple macro with a couple of Image Searches that works and send me the script?
gregster
Posts: 9001
Joined: 30 Sep 2013, 06:48

Re: What's wrong with Else If

Post by gregster » 31 May 2021, 12:59

So what is the goal, which branch should be triggered if the first image is found (If !errorlevel) ?

what are the three cases you are trying to distinguish? Errorlevel 0, 1 and 2 ?
or just 'Image found' vs 'Image not found' (two cases) ? But for both imagesearches?

please describe exactly what should happen!
It's not clear from the code or the request.
User avatar
Muhammadi
Posts: 36
Joined: 27 May 2021, 20:00

Re: What's wrong with Else If

Post by Muhammadi » 31 May 2021, 13:20

The goal:
Look for the first image;
If you didn't find the first image, look for the second image;
If you didn't find the second image, then give the message A;
otherwise give the message B.

In other words:
If you didn't find neither image 1 nor 2, give message A.
If you found either image 1 or 2, give message B.

I've attached a screenshot of the macro.
Attachments
Else If.jpg
Else If.jpg (110.39 KiB) Viewed 1334 times
gregster
Posts: 9001
Joined: 30 Sep 2013, 06:48

Re: What's wrong with Else If

Post by gregster » 31 May 2021, 13:46

Muhammadi wrote:
31 May 2021, 13:20
In other words:
If you didn't find neither image 1 nor 2, give message A.
If you found either image 1 or 2, give message B.
Try

Code: Select all

CoordMode, Pixel, Window
ImageSearch, FoundX, FoundY, 334, 456, 416, 491, C:\Users\KILLERWHALE\AppData\Roaming\MacroCreator\Screenshots\Screen_20210531073118.png
Sleep, 1111
If (ErrorLevel)		; if Image 1 not found 
{
  	CoordMode, Pixel, Window
  	ImageSearch, FoundX, FoundY, 330, 459, 419, 510, C:\Users\KILLERWHALE\AppData\Roaming\MacroCreator\Screenshots\Screen_20210531165725.png
  	CenterImgSrchCoords("C:\Users\KILLERWHALE\AppData\Roaming\MacroCreator\Screenshots\Screen_20210531165725.png", FoundX, FoundY)
  	Sleep, 1111
	If (ErrorLevel)		; if image 2 wasn't found either
	{
    	MsgBox, 0, , A
	}
}

If !(ErrorLevel)		; if Errorlevel is 0  =  either image 1 or 2 was found
	MsgBox, 0, , B
User avatar
Muhammadi
Posts: 36
Joined: 27 May 2021, 20:00

Re: What's wrong with Else If

Post by Muhammadi » 31 May 2021, 14:35

gregster wrote:
31 May 2021, 13:46

Code: Select all

If !(ErrorLevel)		; if Errorlevel is 0  =  either image 1 or 2 was found
Can you tell me how to write this one in PMC?
gregster
Posts: 9001
Joined: 30 Sep 2013, 06:48

Re: What's wrong with Else If

Post by gregster » 31 May 2021, 15:05

Not really, sorry, never used it.

But ! means (logical) not. You could also check If (Errorlevel = 0) for this, if that's easier to find - meaning 'Image found'.

Looking at the screenshot, it could be something like If Image/Pixel Found or something equivalent - but that's just a guess.
Last edited by gregster on 31 May 2021, 15:06, edited 1 time in total.
User avatar
Muhammadi
Posts: 36
Joined: 27 May 2021, 20:00

Re: What's wrong with Else If

Post by Muhammadi » 01 Jun 2021, 04:39

@gregster
I wrote your script, it didn't work.
Thanks anyway.
Post Reply

Return to “Pulovers Macro Creator”