a little help with "find" script

Mike Bonner bonnmike at gmail.com
Sat Mar 10 20:23:16 EST 2012


The result will contain "not found" if there is no match, and also on the
find after the last chunk is found at which points it resets to the start.

Something like the following is pretty straight forward, could be adjusted
to accept card names as an additional argument so you could loop through
all the cardnames (think thats already been suggested?)

And then have the inner loop call the find function to build up your lists
of foundchunks.

on mouseUp
-- could add a repeat for each line tName in the cardnames of this stack..
   repeat until (findIt("asd","foo")) is "not found"
      put the foundchunk & return after tVar
   end repeat
end mouseUp

function findit tString,tField --could add a card name argument and adjust
the find.
   find tstring in field tField
   return the result
end findit



On Sat, Mar 10, 2012 at 6:05 PM, Timothy Miller <
gandalf at doctortimothymiller.com> wrote:

>
> 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
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



More information about the use-livecode mailing list