Referencing a stack from a front script

Tereza Snyder tereza at califex.com
Fri Apr 16 19:13:26 EDT 2010


On Apr 16, 2010, at 1:50 PM, Peter Haworth wrote:

> My app inserts some front scripts from a separate .rev file, then calls a handler in the front script that needs to reference the application's .rev file, specifically to create a stack as a substack of the application's main stack if it doesn't already exist , then add several cards to it.
> 
> Up to now, the front scripts have been in the same .rev file as my app and the code to achieve the above worked fine. I have now broken them out into a separate code library .rev file and things don;t work correctly any more.
> 
> I've tried so many combinations of "this stack", the long name of this stack", etc that I've lost track of what happened with each of them, suffice it to say that none of them had the desired effect.  The .rev file holding the front scripts happens to have a stack with the same name as the stack I want to create in the application's .rev file and I have not been able to figure out how to have the check for the existence of this stack look in the app's .rev file instead of the front scripts .rev file.
> 
> In desperation, I created the stack in the app's .rev file in the IDE, but now how do I tell the create card command in the front script to put the new card into the stack in the app's .rev file - that command doesn't seem to have a way to name the stack you want to create the card in other than what is in the defaultStack and it appears defaultStack can only be set the a local stack name.

First, having two stacks with the same name in memory is a no-no. Change your strategy so that it never happens.

Second, communicate the app stack's name to the handler.  If possible, send a parameter with the stack's name to the handler, or set a property on the object to which the front script belongs and have the handler check for (something like) "the uTargetStackName" of me", or put the stack's name in a global. 

Third, in your handler, create your new substack, set its mainStack to the app stack. Store the value of the defaultStack, set the defaultStack to the new substack, create your cards, and reset the defaultStack. 

I don't know if it suits your design, but I'd put my library code in a stack script, and make a prototype substack of that library stack and call it something like "xxxTemplate" . Then, in the make-a-substack-and-create-cards handler I would clone that stack with 'clone stack "xxxTemplate"', then set the name of it to "xxx", then set its mainstack as above.


t






-- 
Tereza Snyder
Califex Software, Inc.
<www.califexsoftware.com>









More information about the use-livecode mailing list