bug, strange behaviour of libraryStack.
Richard Gaskin
ambassador at fourthworld.com
Thu May 25 11:04:48 EDT 2006
J. Landman Gay wrote:
> Andre Garzia wrote:
>> Dar,
>>
>> I thought of that too, no libraryStack touches the global. The first
>> thing I thought (after hitting my head in the wall a little) was: "hey,
>> I must be emptying the global somewhere in the libraryStack of the
>> mainStack", but no, I never touch it...
>>
>> its very strange. I am now double checking my code. Also, removing the
>> 'library' call made everything work again...
>
> The "library" command is relatively new, compared to other options. Does
> the same thing happen if you instead use "start using stack <whatever>"
> or "insert script of stack <whatever> into back"? These two commands
> produce the same results and have been in the language longer. If those
> work and "library" doesn't, then you may have found a new...feature.
There's an interesting aspect of the libraryStack message which may be a
red herring here or may be worth exploring:
The libraryStack message is sent to a stack whenever the stack is
brought into the message path with the "start using" command*. But
because the stack goes into the message path, any other stacks in the
message path will also get the libraryStack message when it's sent to
any stacks brought into use if that stack passes the message.
While I generally believe it's good form to pass system messages unless
you know up front you'll absolutely never need the message downstream,
Rob Cozens has turned me around on this one. The libraryStack message
is just too easy to catch more than once, and to accomodate the
possibility that other stacks may pass it you'll want something like
this in your libraryStack handler:
on libraryStack
if the short name of the target is the short name of me then
-- do initialization sturf
else pass libraryStack
end libraryStack
That way a libraryStack message sent directly to it gets handled, but
any such messages merely passed to it get passed without being handled.
Given all this, there's the possibility that another stack's
libraryStack message is being handled in your stack, reinitializing the
global you're having trouble with.
You could double-check that with a breakpoint, but it might be even
easier to just add a line with an answer command to notify you when the
message is handled:
on libraryStack
global gMyTroubledGlobal
answer the short name of the target &cr& gMyTroubledGlobal
if the short name of the target is the short name of me then
-- do initialization sturf
else pass libraryStack
end libraryStack
Like I said this may be a red herring, but I've had cases of redundant
initialization myself (before I adopted Rob's advice <g>), so it may be
worth checking out.
* For those of you getting started with Rev and going to RevCon West,
Dan has me scheduled to cover the message path in a session there where
we'll discuss effective use of libraries, frontScripts, and backScripts too.
--
Richard Gaskin
Fourth World Media Corporation
___________________________________________________________
Ambassador at FourthWorld.com http://www.FourthWorld.com
More information about the use-livecode
mailing list