Page 1 of 1

Substacks run OpenStack from main stack

Posted: Thu Feb 14, 2013 8:59 pm
by lohill
I have a problem that just started today. It was happening before I upgraded from 5.5.3 and is still happening after the upgrade to 5.5.4. This is on a Mac. My program has a main stack and about 10 substacks a few of which are opened modally but for the most part the substacks perform the various functions of my program. My problem is that when I want to open one of the substacks the preOpenStack is executed as expected and then for most of the substacks (but not all) the openStack code for the main stack is executed next. This causes a problem because the objects on the substacks differ from those on the main stack.

The main stack and all the subStacks have this same code:

Code: Select all

on preOpenStack
     if the platform is "MacOS" then
          set the textFont of this stack to "Lucida Grande"
     else if the platform is "Win32" then
          set the textFont of this stack to "Tahoma"
     else // linux
          set the textFont of this stack to "Arial"
     end if
   set the textsize of this stack to 12
end preOpenStack
If I put a break point at the step 'end PreOpenStack' on a substack that displays this problem, the 'step' to the next executable command is to the first step of the openStack event of the main stack rather than to the openStack of the substack as it should. A quick check of the two substacks that open without a problem shows that neither one has an OpenCard script.

Can you offer any suggestions of an approach to correct this problem?

Thanks,
Larry

Re: Substacks run OpenStack from main stack

Posted: Thu Feb 14, 2013 11:24 pm
by lohill
I solved this by putting the following script in each stack that didn't already have an openStack script.

Code: Select all

on OpenStack
   put "X" into tVar
end OpenStack
And I must say that this is certainly not the only flakey thing I have seen in this programming environment.

Larry

Re: Substacks run OpenStack from main stack

Posted: Fri Feb 15, 2013 1:21 am
by FourthWorld
Many of us avoid the need for stub handlers but just putting mainstack init code in the script of that stack's first card, which will be first in line to get the preOpenStack and openStack messsages, yet will never inherit those messages from substacks.

Re: Substacks run OpenStack from main stack

Posted: Fri Feb 15, 2013 8:13 am
by jacque
It's only flakey until you see how it works, and then it all falls into place. What you're seeing here is the message hierarchy at work. Event messages are sent to the current card. If there is no handler there to catch it, the message travels through the hierarchy until it is either caught by a handler or is thrown away by the engine. Substacks pass messages to the main stack script, and yours is catching it.

You can do what Richard suggested -- put the handler in the first card of the mainstack, which isn't in the hierarchy when messages pass from substacks. Or you can do what you did -- put a blank handler in as a trap to stop the message. You don't need any content, just the message name itself will do, like this:

Code: Select all

on openStack
end openstack
Or third, you can put a test at the top of your openstack handler to see if the message applies to the mainstack or not:

Code: Select all

on openStack
 if the target is not me then pass openStack -- (or exit openstack)
 ...
end openStack
All three of these methods will deal with messages that pass to your mainstack but shouldn't be handled. Richard's way is best for things like preOpenStack and openStack, because those messages are always sent to the first card of the mainstack when it opens.

There was a link somewhere here that pointed to info about the message hierarchy. You'll probably be frustrated until you know how it works.

Re: Substacks run OpenStack from main stack

Posted: Fri Feb 15, 2013 1:23 pm
by Klaus

Re: Substacks run OpenStack from main stack

Posted: Thu Feb 21, 2013 7:56 pm
by lohill
Thanks Jacque and Klaus.

All these responses were very helpful.

Regards,
Larry