Substack problem .... !

Ken Ray kray at sonsothunder.com
Wed Feb 15 14:20:31 EST 2006


On 2/15/06 7:24 AM, "Francis Nugent Dixon" <effendi at wanadoo.fr> wrote:

> Hi,
> 
> Just arrived on the forum - so Hi to all members !

Hi, Francis! Welcome to the Revolution! ;-)
 
> OK - So I made the plunge to DreamCard after 15 years (and Oh so
> many stacks !) of Hypercard.
> 
> The only problem I have (at the moment) is the MainStack/Substack
> concept. I spent a whole day trawling previous posts to find an answer,
> and fell asleep on my keyboard - you guys obviously know a lot ! But I
> didn't find a solution I could understand.

OK, here's the basic situation with substacks and mainstacks (please excuse
me if I go over stuff you already know):

When you create a stack and save it to disk, the file that contains the
stack is called a 'stackfile'.  Every stackfile contains either a single
mainstack, or a mainstack with one or more substacks.

Substacks and mainstacks are the same (i.e. they both get cards, buttons,
etc.), but you need to understand the following:

- A substack is a substack because its 'mainstack' property has been set to
the name of another existing/open stack (i.e. they are "owned" by another
stack);mainstacks are mainstacks because their 'mainstack' property is the
same name as themselves (that is, they aren't "owned" by any stack; they
"own" themselves).

- All stacks have a 'filename' property that contains the path to where the
stack resides on disk (i.e. the location of the stackfile). Mainstacks have
a filename property that contains a path; substacks have a filename property
that is empty (because they are not independent, but are owned by the
mainstack). If you ever want to know the path to the stackfile that contains
the substack, you can as for 'the effective filename of <substack>", or for
'the filename of stack (the mainstack of <substack>)'.

- If a stack is created on the fly (like "create stack"), the stack is
sitting around in memory without having a corresponding stackfile; to be
able to save the stack to disk, you need to set the fileName of the stack to
a valid path, and then save it with the "save stack" command.

- To convert a substack to become a normal stack (a mainstack), you simply
set its 'mainstack' property to its own name, and then it becomes like a
stack created on the fly; you need to then set the filename and save it to
disk in order for it to have a corresponding stackfile.

For example, if I have a mainstack called "Main" and it has a substack
called "Sub", and the stack file location is "/Users/kenray/mystuff.rev",
here's how this all pans out:

the filename of stack "Main"
--> /Users/kenray/mystuff.rev

the filename of stack "Sub"
--> (empty)

the filename of stack "Sub" of stack "Main"
--> (empty - although the description is more precise, it's still referring
--> to the substack)

the effective filename of stack "Sub"
--> /Users/kenray/mystuff.rev

And now to save "Sub" as its own stack:

set the mainstack of stack "Sub" of stack "Main" to empty
set the filename of stack "Sub" to "/Users/kenray/mysub.rev"
save stack "Sub"

Once this happens, you have *MOVED* the substack out of the stackfile that
contains stack "Main" and into a separate file:

put the substacks of stack "Main"
--> (empty, no longer has a substack "Sub")

and now you have two mainstacks - one called "Main" at
"/Users/kenray/mystuff.rev" and the other called "Sub" at
"/users/kenray/mysub.rev".

In order to *COPY* a substack from one mainstack to another, you need to
clone the substack (which will make it a mainstack just sitting in memory
without a stackfile) and then set the clone's 'mainstack' property to the
same name as the new "parent". So for example, suppose I had one mainstack
called "Main" with a substack called "Sub". I then open another mainstack
called "Main2" and want to give it a copy of "Sub" as a substack. Here's how
you do it:

  clone stack "Sub"
  -- puts the identifier of the new stack into 'it'
  set the mainstack of it to "Main2"
  -- then optionally save it
  save stack "Sub"

Hope this helps...

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