Looping Over Groups?
Jeanne A. E. DeVoto
jeanne at runrev.com
Wed Sep 18 17:45:01 EDT 2002
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/
More information about the use-livecode
mailing list