AnyImageFound: variable input?

I would like to use a list variable as input to AnyImageFound:

put (“image1”, “image2”, “image3”) into foo

if AnyImageFound (foo) then

end if

But that doesn’t work–it tries to load “image1, image2, image3” as one string.

For now, I’m doing it this way:

repeat with each item in foo
if ImageFound (it) then
put it into foundImage
put true into imageWasFound
end if
end repeat

if imageWasFound

end if

This works fine, but it’s slower than the seven-year itch.

Is there a better way? I can’t hard-code the arguments into the AnyImageFound statement, because they’re context-dependent.

I don’t know if there is an easier way, but at least this works:

put ("image1", "image2", "image3") into foo

do "get anyImageFound" & foo
if it then
end if

Excellent answer!

Here’s a slightly simpler version, using the value() function as an alternative to “do”:

put ("image1", "image2", "image3") into foo 

if value("anyImageFound" & foo) then 
? ?... 
end if 

These are cool (and it’s good to know that there are techniques for executing arbitrary strings).

Unfortunately, both versions only work for images in the top-level directory. This:

put (“imagedir1/image1”, “imagedir2/image2”) into foo
if value(“anyImageFound” & foo) then
put “whee!”
end if

gives the error:

STInvalidNumberException Value is not a number: IMAGEDIR1

Is there a way to force SenseTalk to see these items as strings rather than expressions? I could change the working directory, but then I’d be back to searching for each item individually, and since all my code is based on building the path strings I’d rather keep it that way.

Yes. The problem is that when SenseTalk creates a text representation of the list (in order to concatenate it with the name of the function) it doesn’t put quotes around your image names. You can force it to do this by setting the listPrefix, listSeparator, and listSuffix properties, like this:

put ("imagedir1/image1", "imagedir2/image2") into foo 
set the listPrefix to <<(">>
set the listSeparator to <<",">>
set the listSuffix to <<")>>
if value("anyImageFound" & foo) then 
    put "whee!" 
end if 

I hope that helps!

Here’s another alternative using a special feature of the “combine” command:

put ("imagedir1/image1", "imagedir2/image2") into foo 
combine foo with "," using quotes
if value("anyImageFound(" & foo & ")") then 
	put "whee!" 
end if 

Fewer lines of code – probably no other advantage beyond showing off some other features of SenseTalk.

Thanks, guys! That does the trick.