How to confirm an image Doesn't show up?

Hi, it’s me again, long time listener, first time caller… I wonder if this is the way to go about this… I want to make sure an image DOES NOT appear? So… how do you do that?

Instead of:

WaitForAny 5.0, “BadImage”

NoWaitForAny ?

Thanks!

Thought you may like this…

params  n, images...

if n is not a positive integer then
	insert n before images
	set n to 3.1415 ^ 2  -- loads of pie!!
end if

-- make for a short search cycle within reason
set oisd to the ImageSearchDelay
set oisc to the ImageSearchCount
set the ImageSearchDelay to 0.1
set the ImageSearchCount to 2

-- search for all images...
set sTime to the long seconds
repeat until the long seconds - sTime > n
	repeat with each item image in images
		if ImageFound(image) then return false
	end repeat
end repeat

-- reset the search speed back to where we came.
set the ImageSearchDelay to oisd
set the ImageSearchCount to oisc

return true  -- no image/s found

Just tossed it together, tested lightly, use accordingly. Tested basic boundary value on 4 and then 5 image set, with various time lengths with expected results.

Couple ways you could go about this.

If you think the image will be up in a reasonable amount of time, you can say

if not imageFound(someImage) then put "Yippee"

but if you need to wait for a bit to make sure, you’d need a try/catch block

try
    waitfor 5, someImage
    catch e
       put "Yippee"
end try

a shorter version (Todd I was paying attention last time we talked :wink:)

try to waitFor 5, someImage
if the exception is not empty then put "Yippee"

You can correct all my errors :wink: on page 95 of the ST manual. The only reason I remember the page number is that I have it up right now.

My eyes just glazed over… oh you silly hardcore coders you! Is there an easier way? Or do I have to step up? Which I can do…

Of course, Todd’s solution is much more elegant :wink:

Try/catch is actually pretty easy. Once you get the hang of it, you’ll find all sorts of uses for it.

What you’re doing is taking advantage of the fact that waitFor throws an exception (error) when it can’t find something.

Think of it as if there’s an error, then do this.

Actually having reread the requirements, I would say Mr. Allen has a very nice simple solution. Mine handles adjustable time along with various images in a list. However, those features were not part of your requirement, nor was the eyes glazing phenom… :slight_smile: We try to keep it simple, and Allen wins the award for simple-to-the-point today!

Yes, Allen’s first approach is probably the simplest. I’d just add that the ImageFound() function can accept an optional time as the first parameter, so you can specify how long you’d like Eggplant to look before deciding that the image won’t show up. Using your original example, it might look like this:

if ImageFound(5.0, "BadImage") then Throw "BadImageFound", "Image BadImage appeared within 5 seconds"

That will throw an exception if the image shows up, just like WaitFor will if an image doesn’t appear. If you would prefer not to throw an exception but just to record the error and proceed, you could do this instead:

if ImageFound(5.0, "BadImage") then LogError "BadImage showed up!"

I like Doug’s solution even better. That’s why they pay him the BigBucks ™

Allen