a little help with "find" script
Timothy Miller
gandalf at doctorTimothyMiller.com
Sat Mar 10 20:05:12 EST 2012
On Mar 9, 2012, at 12:28 PM, Timothy Miller wrote:
> Oops. Forgot how to do this. Knew it once. I don't write scripts every day. Not even every month.
>
> Please remind me how to write a script that finds and records every instance of a string in field "foo" I know how to write repeat loops, but can't remember how to keep finding and then exit when the last instance is found.
Predictably, I didn't understand the advice I got, though I do appreciate it. With enough study, I could have figured it out. Instead, I tried to remember the way I've done it in the past, combined with trial and error.
The string I want to find is "Card ID"
I came up with this
repeat
find string "card ID" in field "narrative"
if the foundChunk is not empty then
put the foundChunk && "of card ID" && the short Id of this card into tVar
if tVar is not among the lines of bigVar then
put tVar & return after bigVar
else
exit repeat
end if
end if
end repeat
This is primitive, hyperCard-like scripting I suppose. That's how homey rolls. It seems to work. Is this a bad way to do it? Is there a clearly better way?
As far as I can tell, in a repeat loop, the "find" command somehow keeps track of the last found item and moves on to find the next one, but repeats forever unless you script some way to detect duplicate foundChunks and exit. Correct?
I have another question before I can make this script do what I want, but I'll start a new thread, to avoid confusion.
Tim
More information about the use-livecode
mailing list