Problem Setting the Mainstack

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Gage
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 224
Joined: Tue Mar 26, 2013 8:59 pm

Problem Setting the Mainstack

Post by Gage » Sun Jul 27, 2014 10:35 pm

Hi all!

Hope everyone is able to restrain their excitement about HTML 5 and the SoCal event next month enough to stay productive! :P

I have an issue where I am currently working on multiple separate stacks, which will eventually be consolidated into one beast app. For now, I am able to operate fine if the Mainstack of each of the pieces I am working on can be set.

HOWEVER, whenever I go to set the Mainstack of my stack to the one I want it to be, it doesn't work properly. There are two cases:

1) I want stack "Mainstack" to be the Mainstack of stack "Stack 3", so I go to the stack "Stack 3" Property Inspector and in the "Basic Properties" pane, select stack "Mainstack" as the mainstack. ASSUMING the selection appears to switch to my chosen stack (which is not always the case), it quickly reverts to stack "Stack 3"

2) Same scenario as above, but instead of using the Property Inspector, I use the Message Box to send the following code:
set the mainstack of stack "Stack 3" to stack "Mainstack"

In this case, I get a popup dialog with:
Script compile error:
Error description:

Soooo, I'm kind of at a loss, here. I need to be able to access custom properties and global variables from stack "Mainstack" while in stack "Stack 3", but can't figure out how to link them permanently (or at least until I choose otherwise).

Hoping y'all can shed some light on this for me!

Thanks in advance!
Phil E.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10102
Joined: Fri Feb 19, 2010 10:17 am

Re: Problem Setting the Mainstack

Post by richmond62 » Sun Jul 27, 2014 10:52 pm

I dunno:

Just made a stack called "MAIN" and another called "SUBORD".

I was able to set the main stack of SUBORD to MAIN with the prefs palette
with not trouble at all.

Here's a thought:

Close Livecode.

Restart Livecode and make 2 stacks just exactly as I did, and set one to be a substack of the other.

Now if that works there's something odd going on with your stacks rather than your Livecode IDE.

If that does NOT work then your IDE is "poisoned"; dump it and reinstall.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Problem Setting the Mainstack

Post by Mark » Sun Jul 27, 2014 11:07 pm

Hi Phil,

It is possible that one of the stacks is protected by a password. That would typically produce the type of error you see when you try to set the mainstack from the message box. It is also possible that stack Mainstack is actually a substack of another mainstack, which makes it impossible to use it as a mainstack for any other stacks. Other possibilities are that the cantDelete or cantModify of any of the stacks involved are set to true or that the mainstackChanged message somehow triggers a handler that contains an error (perhaps somewhere in the IDE). A reason for an error to happen could be the actual name of the stack. E.g. if the name is a number, there is a big chance to create all kinds of problems. Some special characters, such as -, /, $ and quote might also cause errors.

To use global variables, you don't need to have substacks and mainstacks. The same applied to custom properties: those are accessed by referencing the correct stack, card or control:

Code: Select all

global gVar

on foo
  put the cYourCustomProperty of stack "Your Stack" into gVar
end foo
Kind regards,

Mark
Last edited by Mark on Mon Jul 28, 2014 12:07 pm, edited 1 time in total.
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Problem Setting the Mainstack

Post by Klaus » Sun Jul 27, 2014 11:11 pm

Hi Phil,

the correct syntax is:
...
set the mainstack of stack "Stack 3" to "Mainstack"
## without an extra STACK before the mainstack anme!
...
Hint: This will fail if your "Stack 3" contains substacks!
Hope that helps!


Best

Klaus

Gage
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 224
Joined: Tue Mar 26, 2013 8:59 pm

Re: Problem Setting the Mainstack

Post by Gage » Sun Jul 27, 2014 11:29 pm

Hi, all, thanks so much for the quick responses!

First of all, Klaus, you are completely correct, and I have been using the correct syntax, I just typed it wrong when I submitted the post. Thank you for your keen eye!

Next, Mark, WOW! That's a ton of incredible insight, thank you! I figured the custom properties would work, but thought that "global" inferred "stack global," so I learned something there. Now, is it possible to access the custom properties of an unopened stack? (I guess I could test this, but I have more of an affinity for the human insight :D ).

Checklist:
-To my knowledge, neither stack is PW protected. Both open just by using the Open command in the IDE's File tab.
-I affirmed that stack "Mainstack" had itself selected as the mainstack, and tried to set the mainstack of stack "Stack 3" to "Mainstack", getting the same results as before.
-cantDelete and cantModify are all unchecked (false).
-Neither stack actually has any non-alphabet characters in its name, despite my example.
-I'm not sure how I can track the mainstackChanged handler, so I haven't checked further into that possibility.

Finally, richmond62, I just tried your suggestion, and I can definitely say that it's not my IDE. I was able to create a substack by both the New Substack selection, as well as creating a new Mainstack and then setting its mainstack to the desired on in the Property Inspector. Great suggestion! So, now, it's time to figure out just why my stack isn't behaving, or to just scrap it and create a new one with all copied objects and scripts.


Thank you all for your help!

Phil E.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Problem Setting the Mainstack

Post by Mark » Sun Jul 27, 2014 11:55 pm

Hi Phil,

Just to be sure.... your stack isn't actually called Mainstack?

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Gage
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 224
Joined: Tue Mar 26, 2013 8:59 pm

Re: Problem Setting the Mainstack

Post by Gage » Mon Jul 28, 2014 6:58 am

Mark,

No, it is called "Communi Main."

Best,
Phil

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Problem Setting the Mainstack

Post by Mark » Mon Jul 28, 2014 12:13 pm

Hi Phil,

You asked if it is possible to access the custom propeties of an unopened stack. Yes, it is, but honestly it still isn't entirely clear to me what happens when you do that. To access an unopened stack, you need to use the relative or absolute path to that stack:

Code: Select all

put specialFolderpath("applications") & "/your app/your stack.livecode" into myPath
put the cSomeCustomProp of stack myPath into myVar
A relative path could be "components/your stack.livecode", which would be a stack in folder components in the current defaultfolder.

It still isn't clear to me whether the stack that is accessed this way is (supposed to be) read into memory but not opened or that it is also actually opened. To make sure that my code works consistently, I just open the stack using the go command first and then access its properties, fields etc.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Problem Setting the Mainstack

Post by jacque » Mon Jul 28, 2014 4:59 pm

Mark wrote: It still isn't clear to me whether the stack that is accessed this way is (supposed to be) read into memory but not opened or that it is also actually opened.
It's opened invisibly and not placed in the message path, the same way a "closed" stack is when its destroystack is false. It will take up memory but otherwise doesn't interfere. After I retrieve a custom property from a stack on disk, I use "delete this stack" to free up the RAM.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Problem Setting the Mainstack

Post by Mark » Mon Jul 28, 2014 5:05 pm

That's also something I don't do: setting the destroyStack property to false. I like to keep things clean, although on rare occasions it might bea good thing to keep a stack in memory. I should play around with this a little more.

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Problem Setting the Mainstack

Post by jacque » Mon Jul 28, 2014 6:50 pm

I don't use destroyStack=false either much. The original purpose, which was to speed up stack loading, is largely moot with today's faster processors. But recently I did find a use for that setting. A stack that stays in RAM keeps its current state, so when you re-open it you are still on the same card and it retains the same setup it was in when it was closed. Also, no openStack message is sent (I can't decide if that's a bug or a feature) so any openstack scripts won't interfere with the current state. There may not be any of the other open* and preopen* messages either, but the only one I used was openStack so that's the only one I'm sure of. Instead of openStack, you get resumeStack, where you can handle anything that needs doing.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Gage
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 224
Joined: Tue Mar 26, 2013 8:59 pm

Re: Problem Setting the Mainstack

Post by Gage » Tue Jul 29, 2014 7:49 pm

Mark and Jacque,

Thanks for the additional depth. That clarifies things for me quite a bit. I do tend to get a little hesitant when opening and closing certain peripheral stacks in various contexts, due to not being sure how LiveCode handles that sort of things (i.e. "Resources" substacks of two different stacks will cause mixups if not named uniquely).

Thanks for the help and feedback!

Cheers,
Phil E.

Post Reply