How to always close a substack when going to another substack?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

trevix
Posts: 960
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

How to always close a substack when going to another substack?

Post by trevix » Fri Sep 30, 2022 3:07 pm

Hello.
This thing is getting me crazy since I thought to have fixed it, but the problem keep returning on me...

- My standalone, running on mobile, is made of a "main" stack and around 15 substacks, each one with several cards.
- The "main" stack becomes invisible after launch, when the code move the UI to substacks. Some service code is in it but should not be a problem for what follows.
- When I move from a substack "comingFrom" to another substack, I need to always run the "openCard" of the substack "goingTo".
- In order to do this, I must be sure that the substack "comingForm" always gets closed when leaving and, before that, eventual pending messages gets cancelled.
- Eventual pending messages on a substack are used to run slow loop (advertising style) between the cards of the substack. So I cannot use the "Closecard" message to simply close the substack.
- On mobile, Android, having two substacks opened and visible sometime confuses the "topStack", so that the standalone gets blocked by the wrong top card.
- "SuspendStack" is not a good solution since the user can leave the standalone for another app and then return to it.(and anyway I use this message for local notifications)

I know how to do all this, but things are getting really confused, because of how my standalone has been constructed.
1) Is there a simple way to accomplish this that I don't know about?
2) Is there a missing "on LeaveStack" message sort of that I can use to close the left over when changing substack?
3) Should I, when going to a substack, use "the openstacks" to always run a loop to close all the other substack ?

I hope to have been cleare enough and thanks for any suggestions...
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9655
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How to always close a substack when going to another substack?

Post by dunbarx » Fri Sep 30, 2022 3:46 pm

Hi.

I am not getting why the "closeStack" message is slowing down your app. In any case, does "closeCard" also do that? Is it possible that you can work that message to your advantage?

"leaveStack" is adorable, but already implemented as "suspendStack" as you already know.

Assuming that closeStack really has such an influence, can you use "openStack" to close all other stacks? This seems like a very roundabout way of doing this, and I wonder if it also will slow things down. You could test for all stacks that are not the topStack...

Craig

trevix
Posts: 960
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: How to always close a substack when going to another substack?

Post by trevix » Fri Sep 30, 2022 6:05 pm

I am not getting why the "closeStack" message is slowing down your app.
Let me explain, is not a matter of slowness:
Making thing simple, there is a substack "BoxLoop" with 3 cards that, when the app is in standby , change every 4 seconds (using send in time).
When my socket library in the standalone receives a message (from another app of mine), the message received is 2 lines that are handle with a "do":

Code: Select all

set the cLoopRunning of stack "BoxLoop" to false
go card "cardXOfOtherSuBstack"
The "BoxLoop" stack script:

Code: Select all

SetProp cLoopRunning pValue
	if not pValue then
		cancel sMessageID --ID of running send, otherwise the close stack won't work
		send "close me" to me in 500 milliseconds
	end if
end cLoopRunning
This code runs fine on desktop, using two different Macs on local network, but on Android sometime gets stuck. (The Android machine is a TvBox not particularly fast and I wonder if I have a problem of "timing").
Assuming that closeStack really has such an influence
Similar situations are in several part of the standalone.
I do most of card preparation and localization on PreOpenCard (actually localization only for long text, using revprofile for control names), so the fact that the PreOpenCard are run is important. If there is a SubStack2 open behind the top SubStack1, the next time I go to SubStack2 the PreOpenCard wont run.
I could use this, as I mentioned:

Code: Select all

On Openstack
  put the short name of me into tIsMe
  put the openstacks into tOpenstacks
  repeat for each line tStack in tOpenstacks
    if not ....-- filter tIsMe  and service stacks
      close stack tStack
   end if
 end repeat
end PreOpenStack
But it seems such an ugly way of doing this....
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>

trevix
Posts: 960
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: How to always close a substack when going to another substack?

Post by trevix » Fri Sep 30, 2022 6:13 pm

I forgot:
I tried to find out what is going on Android using the remote debugger (which I bought) but for some reason (local network confusion?) the remote debugger does not stop any more after the first breakpoint.
PS Let me tell you...the remote debugger need a serious rework, in my opinion. It is alway failing randomly, particularly showing variables.
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>

Klaus
Posts: 13823
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to always close a substack when going to another substack?

Post by Klaus » Fri Sep 30, 2022 6:32 pm

Not sure I really understand your problem since LC will load a complete stack including substacks into RAM
so there may be no difference if the stack is "open" or not.

If you want to close a stack after going to another one I would do something like:

Code: Select all

...
put the short name of this stack into tOldOne
go stack "the other substack"
close stack tOldOne
...

trevix
Posts: 960
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: How to always close a substack when going to another substack?

Post by trevix » Fri Sep 30, 2022 6:38 pm

The difference is that if the stack is open, albeit behind another, going to its first card will not run the preOpencard message.
At least, this happens on Android.
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>

Klaus
Posts: 13823
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to always close a substack when going to another substack?

Post by Klaus » Fri Sep 30, 2022 6:50 pm

AHA! :-)
OK, get it now, thanks.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9655
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How to always close a substack when going to another substack?

Post by dunbarx » Fri Sep 30, 2022 7:30 pm

Well, if you really cannot use "suspendStack" and resumeStack", and of course you know these two are just what you need, you can always make a kludge and a half.

I made two stacks. On the first one I made a button that was as large as the card, and put this in its script;

Code: Select all

on mouseWithin
   if the newlyOpened of this card is "true" then
      set the newlyOpened of this card to "false"
      beep 3
   end if
end mouseWithin

on mouseLeave
   set the newlyOpened of this card to "true"
end mouseLeave
If I navigate to the second card and go back to the first, I get three beeps. Did I mention this was a kludge? Put the button behind all the other controls and make it unobtrusive. Now change the beep line into a call to some useful handler. But does this do it?

Craig

trevix
Posts: 960
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: How to always close a substack when going to another substack?

Post by trevix » Sat Oct 01, 2022 9:03 am

mmmh....thanks but this is going to make my standalone rather difficult to control, since I am using MouseLeave in controls.

I was wondering how much am I going into trouble if I use a global to keep the name of previous substack and be able to always close it.

Code: Select all

global gClosingStack
on OpenStack
   if gClosingStack is not empty AND gClosingStack <> the short name of me then close stack gClosingStack --just in case
    put the short name of me into gClosingStack
end Openstack
What could go wrong?
Then there is the "destroyStack" property: does it apply to substacks also or just to stacks. The alarming msg in the dictionary makes me puzzled:
...If you open and close many stacks in a session, and the destroyStack of all these stacks is false, the memory used by these stacks will continue growing until you quit the application.
I have to modify a lot of stuff in my standalone, in order to implement this, so any suggestion is welcomed.
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9655
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How to always close a substack when going to another substack?

Post by dunbarx » Sat Oct 01, 2022 5:14 pm

Well. as for using "mouseLeave" in other controls, you can always pass it along.

And as for using a global instead of a custom property, why? They do the same thing, sort of, but custom properties survive sessions, so you do not have to load them each time.

And as for taking this kludgey pathway seriously, I never thought it actually an option. But kludges work as well as any other methodology, as long as they are well constructed. The main issue is to make sure that the card sized "invisible" button does not get in its own way, or in the way of anything else.

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9655
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How to always close a substack when going to another substack?

Post by dunbarx » Sat Oct 01, 2022 5:20 pm

I never actually understood the "destroyStack" property, even though I use it. Stacks seem to linger in memory somehow regardless. Jacque had some things to say on this years ago.

Anyway, apart from taking up memory, which should not be an issue these days (stacks in the IDE only take kiloBytes of memory) I doubt you will ever have to think about this.

Craig

trevix
Posts: 960
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: How to always close a substack when going to another substack?

Post by trevix » Sun Oct 02, 2022 8:35 am

Schermata 2022-10-02 alle 09.34.23.png
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7227
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: How to always close a substack when going to another substack?

Post by jacque » Sun Oct 02, 2022 5:23 pm

dunbarx wrote:
Sat Oct 01, 2022 5:20 pm
I never actually understood the "destroyStack" property, even though I use it. Stacks seem to linger in memory somehow regardless. Jacque had some things to say on this years ago.
Destroystack is the same as the menu item "Close and remove from memory". It ensures that whenever the user clicks the close box in the title bar, the stack is completely removed. However, it does not apply to substacks because the entire stackfile is always kept in memory.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9823
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: How to always close a substack when going to another substack?

Post by FourthWorld » Sun Oct 02, 2022 6:35 pm

Does "go...in window..." not work on Android?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

trevix
Posts: 960
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: How to always close a substack when going to another substack?

Post by trevix » Sun Oct 02, 2022 8:31 pm

Hello.
The last I know on "go..in window", is the 2018 conversation https://www.mail-archive.com/use-liveco ... 91646.html and related bug, which is somehow difficult for me to follow (but apparently solved).
"...In window" is always been a rather obscure method. Scarce mentions on the dictionary, impossible to search on the forum search, etc.

Are you suggesting that this method works fine on mobile platforms, for going back and forth from substack to substack and have the "openStack", "open card", etc. always sent, no matter what?

Code: Select all

go card "x" of stack "ShortNameOfNewStack" in window of "ShortNameOfOldStack"
That is, the "in window" close the "ShortNameOfOldStack" substack? Even on Android?
Thanks
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”