Imagesearch returns X and Y values swapped Topic is solved
Imagesearch returns X and Y values swapped
If I understand the syntax correctly, the first output variable name I specify will be assigned the X value of the search result, and the second output variable name I specify will be assigned the Y value of the search result.
I'm getting the returned values swapped. The first output variable name I specify is getting assigned the Y value of the search result, and the second output variable name I specify is getting assigned the X value of the search result.
TIA for any guidance on why this is happening.
I'm getting the returned values swapped. The first output variable name I specify is getting assigned the Y value of the search result, and the second output variable name I specify is getting assigned the X value of the search result.
TIA for any guidance on why this is happening.
Re: Imagesearch returns X and Y values swapped
That's not really possible. Please post your script (between [code][/code] tags), the results you're getting, and what you think the results should be.
Re: Imagesearch returns X and Y values swapped
Welcome to this AutoHotkey forum!
If multiple images exist, it is possible for the images to exist in a way that the unexpected image is found and happens to have the inverted coordinates.
If multiple images exist, it is possible for the images to exist in a way that the unexpected image is found and happens to have the inverted coordinates.
Since the search starts at the top row of the region and moves downward, if there is more than one match, the one closest to the top will be found.
Re: Imagesearch returns X and Y values swapped
You are correct: the values for X and Y are being assigned correctly to the output variables. My confusion arose from not understanding the behavior of MsgBox.
I expected things to appear in the MsgBox pop-up in the same order as in my code -- but this is not so, as seen in this example. From my code, I expected the X output variable to be shown, then the Y output variable -- but that's not the sequence in which MsgBox displayed the variables.
I expected things to appear in the MsgBox pop-up in the same order as in my code -- but this is not so, as seen in this example. From my code, I expected the X output variable to be shown, then the Y output variable -- but that's not the sequence in which MsgBox displayed the variables.
Code: Select all
FoundX := "0"
FoundY := "0"
ImageSearch &FoundX, &FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, "Target.png"
MouseMove FoundX, FoundY
MsgBox "X =" FoundX, "Y =" FoundY
Re: Imagesearch returns X and Y values swapped Topic is solved
It's not that MsgBox puts them in the wrong order. The issue is that you put them in two different parameters. You put the X value in the Text parameter, and since you separated the two values with a comma, your Y value ended up in the Title parameter, making it appear "first" to you.
Re: Imagesearch returns X and Y values swapped
Here is a fix if you need it.
The moral of the story is not how to use the MsgBox function. It is the value of posting your problematic script for readers to examine and test. Doing that in the first post saves everyone a bunch of time and effort.
Code: Select all
#Requires AutoHotkey v2.0
FoundX := 1
FoundY := 2
MsgBox 'X = ' FoundX '`nY = ' FoundY, 'Coordinates'
Re: Imagesearch returns X and Y values swapped
Now I understand! Thanks.boiler wrote: ↑30 Mar 2023, 09:00It's not that MsgBox puts them in the wrong order. The issue is that you put them in two different parameters. You put the X value in the Text parameter, and since you separated the two values with a comma, your Y value ended up in the Title parameter, making it appear "first" to you.