Looping Over Groups?

Ken Ray kray at sonsothunder.com
Mon Sep 23 23:09:01 EDT 2002


Jim,

Try this for your second line:

  answer the name of image i in group "players_group"

The problem is that the number of the images change when you add an image to
the card.

Ken Ray
Sons of Thunder Software
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/

----- Original Message -----
From: "Jim Biancolo" <webmaster at listology.com>
To: <use-revolution at lists.runrev.com>
Sent: Monday, September 23, 2002 10:05 PM
Subject: Re: Looping Over Groups?


> Hi folks,
>
> I've run into an additional problem here, and I hope you can help . . .
>
> I've created a group of 14 images.  As advised, I loop over them like so:
>
>      repeat with i = 1 to the number of images in group "players_group"
>        answer the name of image i
>      end repeat
>
> Works great.  When I click on the "Object --> Edit Group" menu, all 14
show
> up as expected.
>
> However, when I add another image to the card (but not to the group) and
> run the same code, the new image is included in the loop (even though it's
> NOT in the group), and the last image in the group is not (even though it
> should be).  When I click on the "Object --> Edit Group" command my
> original 14 images are there and the new image is not, which is what I'd
> expect.  It's the looping behavior that is not what I'd expect.  It seems
> (just guessing though) to be pulling the image at positions 1 through 14
> regardless of whether or not they are in the group.  Am I doing something
> wrong, or is there another approach I should be taking?
>
> Thanks!
>
> Jim
>
> At 03:42 PM 9/18/2002 -0700, you wrote:
> >At 3:09 PM -0700 9/18/2002, Jim Biancolo wrote:
> > >Is there a way to loop over the images in a group?  I tried these:
> > >
> > >    repeat for each image I in group "my_group"
> > >    repeat for each item I in group "my_group"
> > >    repeat for each object O in group "players_group"
> > >
> > >All failed to compile.  Then I hit on:
> > >
> > >    repeat for each element E in group "players_group"
> > >
> > >It compiled, but then when I tried to run it I got this error:
> > >
> > >    Error description:  Chunk: source is not a container
> > >
> > >I fear I'm missing something obvious.  Any advice?
> >
> >I think people have been so enthusiastic about advising the efficient
> >"repeat for each" form that the other forms have gotten a little
eclipsed.
> >;-)
> >
> >The "repeat for each" form can be used to iterate over chunks in a
string -
> >characters, words, lines, items - or over each element in an array, but
it
> >can't be used to iterate over objects. The first and third variations you
> >tried wouldn't compile because "repeat for each image" and "repeat for
each
> >object" aren't valid forms of the repeat loop. The second one, "repeat
for
> >each item", is valid... but in this context, an "item" is a part of a
> >string, not an object, so this doesn't work either. And the fourth, while
a
> >valid form, requires an array, not a group reference.
> >
> >Here's a form that will work:
> >
> >   repeat with x = 1 to the number of images in group "my_group"
> >     answer the name of image x -- or whatever
> >   end repeat
> >
> >--
> >Jeanne A. E. DeVoto ~ jeanne at runrev.com
> >Runtime Revolution Limited - The Solution for Software Development
> >http://www.runrev.com/
> >
> >
> >_______________________________________________
> >use-revolution mailing list
> >use-revolution at lists.runrev.com
> >http://lists.runrev.com/mailman/listinfo/use-revolution
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/use-revolution
>




More information about the use-livecode mailing list