finding in script

Wilhelm Sanke sanke at
Tue Jan 4 18:04:46 EST 2005

On Mon, 3 Jan 2005 "Jeanne A. E. DeVoto" <revolution at> wrote:

> (snip)
> >>>>The real problem here is that you can't get a list of all the
> >>>>groups in a stack any more since backgroundBehavior was introduced.
> >>>>But that's a rant for another day....
> >
> >>
> >>Sure, you can!  Check the docs for the "backgroundIDs" and
> >>"groupIDs" properties (they are not the same thing).
> Since 1.1 (when the backgroundBehavior property was added), the
> backgroundNames and backgroundIDs only report groups with that
> property set to true. So they won't give you all groups in a stack,
> just those with backgroundBehavior.
> -- jeanne a. e. devoto ~ revolution at

You must have missed my post of Mon, 03 Jan 2005 22:16:10 +0100 
(probably because of the different time zones), so I will repeat part of 
it and make some additions.
"backgroundnames" and "backgroundIDs" will indeed list only those 
primary (unnested) backgrounds with backgroundbehavior set to true.

However "the number of backgrounds" does *not* distinguish between 
backgrounds with true or false backgroundbehavior, and it will return 
the number of *all* primary, i.e. unnested, backgrounds.
Using "number of backgrounds" to set up a list of backgrounds 
unfortunately works only correctly when no *nested* backgrounds exist.

Let us assume you have got 10 primary backgrounds plus 1 nested 
background attached to primary background 2.
You have a total of 11 backgrounds now, but "number of backgrounds" 
returns only 10.
When you script "put the name of background 3" this however refers to 
the total number of backgrounds (11) and will therefore return the name 
of the additional nested background grouped with background number 2.
So you cannot really rely on the value returned by "number of 
backgrounds" to set up a list if you want to get the names (or other 
properties) of each background.

As far as I can see, such information is not included in the documentation.

If you wish to list *all* existing backgrounds - nested or not, placed 
on a card or unplaced, backgroundbehavior true or not - you can script 
this using a counter variable.

"on mouseUp
  put the name of the topstack into SName
  put empty into BList
  put 0 into counter
    add 1 to counter
    if there is a background counter of stack SName then
      put the name of background counter of stack SName  into line 
counter of BList
      exit repeat
    end if
  end repeat
  put Blist into fld "Blist"
end mouseUp"

This script could be refined to indicate grouped backgrounds, unplaced 
backgrounds, and the backgroundbehavior of each background.-

Seen from one side, handling groups and backgrounds became indeed 
somewhat more complicated when "backgroundbehavior" was added. I regret 
having contributed to this complexity as Scott Raney introduced the 
backgroundbehavior property following an enhancement request from my side.
On the other hand, the new option to work with groups without 
backgroundbehavior (i.e. set to false) facilitates scripting in quite a 
number of cases because adapting to the message hierarchy is now easier 
- when all you want is just to group two controls and handle them as an 
entity without any background behaviors in mind.

--Wilhelm Sanke

More information about the Use-livecode mailing list