How to save all X,Y positions found in one image search loop to different variables?
My image search in a loop finds a random number of yellow squares (this time 3 squares, sometimes more). It right-clicks a yellow square that then disappears (which helps find the next square instantly). It right-clicks one again and so forth. It breaks the loop when there are no more squares to find (they disappear one by one).
It works, but how to save all 3 positions found as 3 different variables (to be called upon later)? I can do it without the loop, but I need the loop.
I'm using feiyue's FINDTEXT function and can't change the code at the beginning :
#Include <FindText>
z::
;;; this is just my initial search of two images to set up my search range which works well.
Text:="|<wcBL_c95>[email protected]$11.VV8GUI0A0s1U1E EYADzk"
if (ok:=FindText(aX, aY, 0, 0, 1918, 1078, 0, 0, Text))
Text:="|<wcTR_c95>[email protected]$11.zy64V 1E0k3U6050d2Ekk"
if (ok:=FindText(bX, bY, 0, 0, 1918, 1078, 0, 0, Text))
;;;===> The above 4 lines search for the coordinates on my screen to look at. You can ignore this part, but this gives me the coordinates RANGE to do my loop search in as seen below: aX, bY, bX, aY
Loop
{
Text:="|<wc\_c100>[email protected]$6.SzzzzSU"
if (ok:=FindText(VarX, VarY, aX 11, bY, bX-11, ay, 0, 0, Text))
{
MouseClick, Right, X, Y, 1, 1 ; This loop finds 3 Sqaures.
VarX1:= % X
VarY1:= % Y ; how do I increment these for the next loops?
}
else break
}
MouseMove, VarX1, VarY1, 1
sleep, 333
MouseMove, VarX2, VarY2, 1 ; Doesn't exist (i need to increment varibales in the loop - HELP!)
sleep, 333
MouseMove, VarX3, VarY3, 1 ; Doesn't exist (i need to increment varibales in the loop - HELP!)
Return
CodePudding user response:
You can just use %A_Index% in your variable when assigning the "x" and "y" values:
if (ok:=FindText(VarX, VarY, aX 11, bY, bX-11, ay, 0, 0, Text)) {
MouseClick, Right, X, Y, 1, 1
VarX%A_Index%:= X
VarY%A_Index%:= Y
}
Here is an example:
x= 10
Loop, 10 {
x
y--
VarX%A_Index% := X
VarY%A_Index% := Y
}
MsgBox % VarX1 "`t" VarY1 "`n"
. VarX2 "`t" VarY2 "`n"
. VarX3 "`t" VarY3 "`n"
. VarX4 "`t" VarY4 "`n"
. VarX5 "`t" VarY5 "`n"
. VarX6 "`t" VarY6 "`n"
. VarX7 "`t" VarY7 "`n"
. VarX8 "`t" VarY8 "`n"
. VarX9 "`t" VarY9 "`n"
. VarX10 "`t" VarY10