I guess I stumped everyone. :(

Ken Ray kray at sonsothunder.com
Thu Nov 3 01:51:11 EST 2005


On 11/2/05 9:51 PM, "Charles Hartman" <charles.hartman at conncoll.edu> wrote:

> 
> On Nov 2, 2005, at 10:42 PM, Charles Hartman wrote:
> 
>>> on openStack
>>>   if the owner of the target is me then
>>>     set the rect of this stack to the screenRect
>>>   else
>>>     pass openStack
>>>   end if
>>> end openStack
> 
> -- but when I do add this bracketing condition to my preOpenStack
> handler in the main stack, I get an execution error (when the handler
> does run). Is there something I don't understand about this? Guess
> there must be . . .

Are you passing "openStack", or "preOpenStack"? The handler should read:

on preOpenStack
  if the owner of the target is me then
    set the rect of this stack to the screenRect
  else
    pass preOpenStack
  end if
end preOpenStack

Basically here's how this works - all the ___stack and ___card messages
(preOpenStack, openCard, etc.) are sent to the card, and then travel through
the hierarchy to the stack. If the stack is a substack, it then travels to
the stack script of the main stack. So a 'preopenstack' message follows one
of these two paths (the location of the handler that traps this has a *
after it):

  card of mainstack -> stack of mainstack* -> (to libraries/backscripts)

OR

  card of substack -> stack of substack -> stack of mainstack* -> (libs/bs)

So the "target" of the message is the card. Checking the "owner of the
target" would be the stack that "owns" the card that got the message. Since
"me" in a script identifies the object that owns the script that's currently
executing, checking to see if "the owner of the target is me" in the
mainstack script basically says "if the recipient of the message is the card
that I own", and so it *doesn't* trigger when a card of a substack is opened
(since the owner of the target of the message is the *substack*, not the
mainstack).

Now a number of other people do it in a simpler (although a bit more
confusing to me) way - all of these message handlers reside in the *card*
script, so to trap the 'preOpenStack' for the mainstack the preOpenStack
handler would be in the script of the first card of the mainstack. When you
do it *this* way, there is no possibility that a substack can trigger this
message because the message passing hierarchy does this:

  card of mainstack* -> stack of mainstack -> (to libraries/backscripts)
AND
  card of substack -> stack of substack -> stack of mainstack -> (libs/bs)

So the mainstack's card isn't in the passing hierarchy for substacks.

The reason I say it's "more confusing to me" is because mentally I associate
___stack messages with a stack and ___card messages with a card, so putting
___stack messages in a card script seems somehow "wrong" (although I know it
really isn't).

Anyway, I've settled on the "owner of the target is me" approach, which has
worked well for me for years. :-)


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




More information about the use-livecode mailing list