Recursion warning: what's the owner of a background?

Peter Brigham MD pmbrig at
Thu Dec 23 07:54:13 EST 2010

On Dec 23, 2010, at 6:34 AM, David Bovill wrote:

> This one just caught me out. I have a script that checks a property  
> of it's
> owner and returns the value. Specifically it checks the owner for a  
> property
> of the same name to see when the local value is empty to see if it is
> defined higher up in the object hierarchy. I thought this would be a  
> safe
> way of implementing object oriented stuff.
> But you get recursion when the control is a background, because the  
> owner of
> a background is the card the background is on, but the card is  
> actually
> below the background in the message hierarchy, so the background  
> script gets
> triggered again when you look for it in the backgrounds owner.
> A recursive tongue twister maybe - but just remember a background's  
> owner is
> itself in scripting terms!

On the other hand, this utility function works fine for me:

function masterBG theObjectRef
    put the long id of the owner of theObjectRef into onr
    if word 1 of onr = "card" then
       return theObjectRef
       return masterBG(onr)
    end if
end masterBG

It returns the highest level group a control belongs to. I have a  
stack with two major backgrounds (switch between making one or the  
other visible with a button). In my custom find function I need to  
know which master background the foundfield is part of, and it may be  
nested in lower level groups, so this tells me which bg to show when a  
string is found, and it works reliably without the recursion problem  

-- Peter

Peter M. Brigham
pmbrig at

More information about the Use-livecode mailing list