I was trying to create a little script to imagesearch a graph, easy if it wasn't for the fact that imagesearch scans from top to bottom and not from left to right.
So, I was trying to adapt my script to my necessities, and I came up with the solution of making it scan vertical-1pixel lines for a combination of vertical pixels. At every iteration, the script modifies the coordinates of the next imagesearch to move to the next right 1-pixel-column.
If I execute the imagesearches in a separate script they all work ok, and find the image and the relative coordinates.
The whole code instead acts really weird. If I put the %% signs on the coordinate variables of the second imagesearch (the one lookind for Dn2.png), both loops stop working. I believe the problem is some kind of deeper error. I tried removing the break to check if that was the problem but it was not. If I remove the %% signs on the coordinates of the imagesearch it doesn't get stuck but neither finds anything, making the whole script useless.
I fear I made some basic mistake in handling variables, but even there I feel my code is acting weird. I started by defining the initial variables as expressions, without % signs as the KB suggests. Then I added the MsgBox you see at the end of the initial declaration only to find out that the script was not initializing the variables correctly. So I started adding a bunch of % where I had variables but I'm now not really sure where I sould put them and where I shouldn't.
So it's probably a silly question, I apologize, but I sincerely tried to fix it with the help of the documentations.
Here's the code, I hope you won't mind helping me a bit!:
Code: Select all
Loop
{
StartX := 632
StartY := 332
EndY := StartY+630
Count := 0
MaxX := 1230
EndX := (StartX+1)
MsgBox, 0, , Variabili %StartX% %StartY% %EndX% %EndY% %MaxX%
Loop
{
CoordMode, Pixel, Screen
ImageSearch, FoundX, FoundY, %StartX%, %StartY%, %EndX%, %EndY%, *10 C:\Users\Jacopo\Dropbox\PlotToMat\Up2.png
If ErrorLevel = 0
{
If (((UpBound = FoundY+1) && (Blank=0)))
{
Goto, EndOne
Sleep, 2000
}
UpBound := (FoundY+1)
Sleep, 300
CoordMode, Pixel, Screen
ImageSearch, FoundX, FoundY, %StartX%, %StartY%, %EndX%, %EndY%, *10 C:\Users\Jacopo\Dropbox\PlotToMat\Dn2.png
If ErrorLevel = 0
{
If (((FoundY+1)-UpBound) >= 13)
{
LoBound := (FoundY+1)
Sleep, 300
FileAppend, %Count%`, %UpBound%`, %LoBound%, C:\Users\Jacopo\Dropbox\PlotToMat\result.txt
Sleep, 2000
Blank := 0
Sleep, 1000
}
Else
{
Goto, EndOne
Sleep, 1000
}
Sleep, 1000
}
}
Else
{
Blank := 1
Count += 1
Sleep, 1000
}
EndOne:
StartX += 1
EndX += 1
Sleep, 500
If StartX >= MaxX
{
Break
}
Sleep, 500
}
Sleep, 1000
}
Return