Error: ...failed to evaluate LastFoundImage.x


I'm occasionally getting an error when trying to store the coordinates of an image in a separate variable

From Engine.log:

2018-11-24 02:47:42 Set Variable to Calculation failed to evaluate LastFoundImage.x
2018-11-24 02:47:42 Set Variable to Calculation failed to evaluate LastFoundImage.x Macro “FindEitherImage” cancelled (while executing Set Variable “LastFoundImageX” To Calculation “LastFoundImage.x”).

I had to put together a mock example so hopefully you'll be able to recreate the issue.

First go to this website, which is just a demonstration of someone's UI animation.

Next, run this macro repeatedly until getting the error.

FindEitherImage.kmmacros (30 KB)

Note: If you're not getting the error then try running it faster and back-to-back (use the keyboard shortcut trigger). While I'm not running it this fast in my own specific use case, this was the only way I could reproduce it in a way I can share with everyone.

What I don't understand is why LastFoundImage.x doesn't have a value. If LastFoundImage was set to %FoundImage%, then where would this value go?

If you think the speed that I'm running this example is an issue, then how does this happen in my use case when I only run it once every 10 seconds or so?

Any idea what could be going on here and how to remedy the situation?

Look at the value of the LastFoundImage variable in the Variables preference pane. Presumably it does not have a sequence of comma separated numbers. Maybe it is empty because the image was not found?

Indeed it is empty, which explains the error. However, the 'Pause Until' action is supposed to wait until the image is found, meaning if it exits from pausing then it means it was found, right?

I'm also testing it now with a timeout set to 5 hours and it returns from the 'Pause Until' immediately, so I'm sure it's not just timing out without having found an image (unless there's a bug?).

For now I'm going to try to work around the issue by checking to see if the value of 'LastFoundImage' is empty and, if so, try again, but I liked it when it worked 100% of the time before :slight_smile:

I suspect the issue you are facing is the fact that there are two screen image tests. One is succeeding, one is failing. In any event, since one succeeded, the Pause Until completes, however since one failed the result of %FoundImage% may be either valid or empty, depending on which finished last (the conditions run in parallel).

So you wont get a reliable result in the FoundImage token in this case.

You will need to expand it to something like:

  • While true
    • If screen contains image one
      • Set variable LastFoundImage to %FoundImage%
      • Exit from Loop
    • If screen contains image two
      • Set variable LastFoundImage to %FoundImage%
      • Exit from Loop

Thank you - that looks like it'll work, although I had already implemented this workaround:

FindEitherImageAsynchronous.kmmacros (31 KB)

Any potential issues?

Yes. That could potentially loop forever depending on the exact internal details and timings of the image search and condition evaluation.

It would be fine only if the FoundImage token gets a random selection of the two screen contains conditions. But it is quite possible you wont get a random selection, you might get the same condition every time, or even almost every time, and that could mean the loop loops forever or for a long time.

Great point! Here's the implementation Peter is referring to:

FindEitherImage.kmmacros (32 KB)

No more errors :slight_smile:
Thanks Peter

1 Like