numbering backgrounds (was: background owners)
miscdas at boxfrog.com
miscdas at boxfrog.com
Wed May 21 10:47:01 EDT 2003
Wilhelm Sanke writes:
> While dealing with the special features of backgrounds we have
> discussed so far under "background owners", I noticed another specialty
> that seems to be undocumented, namely how to refer to backgrounds by
> number:
>
> As stated in the documentation, the backgroundnames and backgroundIDs
> functions return the "toplevel" backgrounds - the primary ones without
> considering nested groups.
>
> "put the number of backgrounds of this stack" likewise returns the
> number of these toplevel backgrounds.
>
> However, if you want to refer to a background by number (which, of
> course, you need not do)
>
> - do something with background x -
>
> you may end up with a background quite different from what you expected,
> because - this is the point -
>
> the *internal* numbering of backgrounds does additionally include all
> nested backgrounds.
>
> "Background 4" may refer to the "toplevel"background number 4 - if
> there are no nested groups, but in case there are nested groups,
> "background 4" could refer to the second-nested group of toplevel
> background 2.
>
> Apparently there is no function to get the total number of backgrounds,
> maybe something like "the effective number of backgrounds" should be
> introduced.
>
> It has to be scripted, as in the following example:
>
> "put 0 into counter
> repeat
> add 1 to counter
> if there is a background counter of stack SName then
> # do something with background counter
> else
> exit repeat
> end if
> end repeat"
>
> The final value of "counter" now contains the total number of
> backgrounds and if you have produced a list of background names or IDs
> with the help of this script, you can now accurately refer to a
> background also by number.
>
> Regards,
>
> Wilhelm Sanke
===============
But, beware if you add groups, ungroup/regroup, because the numbering will
almost always change. This is another case where it is usually better to use
ID values or names than numbers.
miscdas
More information about the use-livecode
mailing list