Can I use everyImageLocation with a local variable?
repeat with each item of item 2 to last of everyImageLocation(buttonLocation)
In this case my local variable buttonLocation is the result of x- and y-coordinates in the grid which has another identical grid on the left side of the screen. So what I want is to select the button on the right side which doesn’t seem to be working, since eggplant always clicks the button on the left.
From what you’re describing, it sounds like you might be feeding coordinates into EveryImageLocation, instead of an image name.
The EveryImageLocation function is going to be looking on the screen for a reference image that’s named after your coordinates, so it’s probably not going to find anything, or if it does, it won’t be what you actually want.
But, in general, there’s absolutely nothing wrong with using EveryImageLocation to look for a variable image or text string. And since it returns a list, stepping through that list using chunk operators as you’re doing will work perfectly as well.
One thing that might catch you up though is that EveryImageLocation will return the locations of the image as they are found, which won’t necessarily line up with the order a human would find them on the screen. Since eggPlant Functional is scanning each row of pixels left to right, then top to bottom, if the grid on the right is one pixel higher than the one on the left, you can end up with the list in an order you’re not expecting.
If you just want to exclude the left half of the screen from your consideration at the moment, it would probably be more consistent to use your SearchRectangle global property to do that. The code will look something like this:
Set the SearchRectangle to (RemoteScreenSize()*(0.5,0),RemoteScreenSize()*(1,1)) //Dynamically look at the screen resolution and then set the search rectangle to the right half of the screen
Repeat with each item of EveryImageLocation(VariableReferenceButtonImageName)
That way, eggPlant will know to only look at the right half of the screen, and will click on every one of your images.
Thanks a lot! The SearchRectangle function is very useful indeed. :idea: