Page 1 of 1

copy to mainstack substack

Posted: Mon Sep 09, 2013 11:07 am
by pascalh4
Hi

Here's another question about stacks manipulation.

Is it possible to copy or clone a mainstack to become the substack of a second mainstack.

In all my tests the copy is always a mainstack.

Pascal

Re: copy to mainstack substack

Posted: Mon Sep 09, 2013 11:49 am
by Klaus
As I wrote in another posting, make your stack a substack with script!
Every "cloned" (and copy/pasted) stack is first a MAINSTACK:
...
clone stack "my stack"
set the mainstack of stack "copy of my stack" to "the other mainstack..."
...

Re: copy to mainstack substack

Posted: Mon Sep 09, 2013 12:31 pm
by pascalh4
Hi Klaus

Ok it works. I did not understand everything at the first explanation.

But I do not understand why it should be noted "the mainstack of stack".
Why not just stack (because at the moment there is no substack)

With a code that starts with "go to" for example, it's not necessary to specify "Mainstack of" to be recognized as a stack. Only his name is required (right?)

So what is the reason for this distinction? (I hope not to be too curious).

Pascal

Re: copy to mainstack substack

Posted: Mon Sep 09, 2013 12:55 pm
by Klaus
Well, that's the ONLY way to make stack "A" a substack of stack "B":
...
set the MAINSTACK of stack "A" to "B"
...
And it is the only command in Livecode where you use the term "MAINSTACK" :D

Re: copy to mainstack substack

Posted: Mon Sep 09, 2013 1:41 pm
by pascalh4
Well I'll try to remember.

Thank you very much. :D

Pascal

Re: copy to mainstack substack

Posted: Mon Sep 09, 2013 11:38 pm
by jacque
pascalh4 wrote:But I do not understand why it should be noted "the mainstack of stack".
Why not just stack (because at the moment there is no substack)
A file on disk can have several stacks in it, but there can only be one primary stack. All the others must be substacks. The primary stack is called the mainstack, and when you set a stack's "mainstack" property, you are telling the engine to attach the stack to the same file on disk as the main stack, which causes it to become a substack.

When referring to a stack in a script, you don't need to specify whether it is a mainstack or not, but when you want to change the relationship of a stack to another one, you can set its mainstack property.

You can also use "mainstack" to find out which stack is the owner of a substack: "put the mainstack of this stack" gives the name of the substack's owner (the primary stack in the file.)