Exit to top?

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

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

Re: Exit to top?

Post by richmond62 » Sun Aug 25, 2024 12:54 am

What's a 'Brit'?

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

Re: Exit to top?

Post by jacque » Sun Aug 25, 2024 2:16 am

richmond62 wrote:
Sun Aug 25, 2024 12:54 am
What's a 'Brit'?
A US cultural expression.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Exit to top?

Post by dunbarx » Sun Aug 25, 2024 3:57 am

Richmond.

You really must lighten up a bit.

Jacque. I live in Manhattan, but my youth was in Texas.

Northerners look down on Southerners. Southerners do look down on Northerners, but only because Northerners look down on Southerners. :D In Texas itself, those in Dallas look down on those in Houston. Why? because they say those in Houston are oil-covered cowboys. The people in Houston look down on those in Dallas, because they say they are just fancy-pants New Yorker wannabes.

Human nature, mostly, and not particularly sinister.

Craig

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

Re: Exit to top?

Post by jacque » Sun Aug 25, 2024 6:48 am

Craig, I didn't know you grew up in Texas. My nephews are there and I love them regardless. They taught me the expression, "he's all hat and no cattle."
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Zax
Posts: 519
Joined: Mon May 28, 2007 10:12 am
Contact:

Re: Exit to top?

Post by Zax » Sun Aug 25, 2024 11:48 am

Sorry to interrupt this ethno-idiomatic discussion ;)
Here is a test stack that shows that the substack exit command does not stop the modal dialog calling script.

ExitTest.livecode.zip
(1.42 KiB) Downloaded 636 times

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

Re: Exit to top?

Post by richmond62 » Sun Aug 25, 2024 12:40 pm

I am a bit worried (especially re Yanks) . . . almost as ridiculous a words as Brits . . . if I lighten up the cork might pop out. 8)

AndyP
Posts: 634
Joined: Wed Aug 27, 2008 12:57 pm
Contact:

Re: Exit to top?

Post by AndyP » Sun Aug 25, 2024 2:56 pm

Wouldn't 'exit to top' in this case stop all execution in the substack and jump back to the calling stack as this is the substacks top?
Andy .... LC CLASSIC ROCKS!

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

Re: Exit to top?

Post by richmond62 » Sun Aug 25, 2024 5:23 pm

Let's try and find out . . .

Here's a stack with a substack:
-
Screenshot 2024-08-25 at 19.37.14.png
-
The script of the button on the substack contains this:

Code: Select all

on mouseUp
   exit to top
end mouseUp
The openCard script of the substack is this:

Code: Select all

on openCard
   put 1 into CYCLE
   repeat until CYCLE > 5000
      move img "ooo" to 50, 200
      wait 5 ticks with messages
      move img "ooo" to 350, 200
      add 1 to CYCLE
   end repeat
end openCard
on clicking the button 'EXIT to Top' the repeat loop in the cardScript stops, but the substack does NOT close.

The button 'CLOSE!' has this:

Code: Select all

on mouseUp
   set the destroyStack of stack "SUBST" to true
   close stack "SUBST"
end mouseUp
On clicking that button the substack vanishes, and the button 'Open Substack' on the main stack refuses to open the substack again.

Here it is, have a play with it.
Attachments
MAINST.livecode.zip
Stack.
(2.6 KiB) Downloaded 783 times

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Exit to top?

Post by dunbarx » Sun Aug 25, 2024 6:51 pm

Zax..

It sure seems as if the repeat loop continues. If I change the style of the stack to anything but "modal", then "exit to top" works as advertised.

Craig

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

Re: Exit to top?

Post by jacque » Sun Aug 25, 2024 6:59 pm

@Zax
Apologies for hijacking your topic. I haven't tested it but try adding a "start using stack <mainstack > to an openstack/opencard handler and see if that extends the message hierarchy to include the calling stack.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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

Re: Exit to top?

Post by richmond62 » Sun Aug 25, 2024 7:03 pm

So, the problem lies with using a modal stack.

Zax
Posts: 519
Joined: Mon May 28, 2007 10:12 am
Contact:

Re: Exit to top?

Post by Zax » Mon Aug 26, 2024 7:19 am

No need to apologize Jacque, you can do whatever you want (on this forum) :D
I just tried "start using..." but it doesn't change anything.

It looks like a bug: in my opinion, exit to top command should really stop all scripts.

richmond62 wrote:
Sun Aug 25, 2024 7:03 pm
So, the problem lies with using a modal stack.
I think so. As Jacque suggested, it may be a scope issue.

stam
Posts: 3060
Joined: Sun Jun 04, 2006 9:39 pm

Re: Exit to top?

Post by stam » Mon Aug 26, 2024 9:33 am

Zax wrote:
Sun Aug 25, 2024 11:48 am
Sorry to interrupt this ethno-idiomatic discussion ;)
Here is a test stack that shows that the substack exit command does not stop the modal dialog calling script.


ExitTest.livecode.zip
So that was interesting... It seems that the combination of calling a modal in the middle of loop greatly restricts what what you can do.
Doing anything that modifies the calling stack raises an error because of this combination I think.

However there are some ways around this.
The "lamest" way of doing this, is just adding a line to the loop within "Click Me" button's repeat with loop:

Code: Select all

   if "STOPPED" is in field "test" then exit mouseUp
However this relies on showing the user text that may be undesirable and is inflexible.



A better way is to set a flag in the substack acting as modal.
While in the example below it's used to break the loop, your can use this to exit the parent handler instead or take any action depending on what the flag is set to (and/or you can set multiple flags for multiple actions).

In your simple example, the following works: in the modal's button btnExit's script, just set a flag as a custom prop of the stack:

Code: Select all

on mouseUp
   set the dialogData to (the short name of me)
   set the uStop of this stack to true ------ set a flag in the substack
   close this stack
   put "   STOPPED BY FLAG" & cr after fld "Test" of stack (the mainStack of this stack)
end mouseUp
in the script of the Click Me button in the mainstack, add a line to take action based on the flag in the modal within the loop:

Code: Select all

on mouseup
   put "" into fld "Test"
   repeat with i = 1 to 10
      if the uStop of stack "Dialog" then exit repeat ------ act on flag in substack
      put "Iteration" && i & cr after fld "Test"
      if (i = 5) then modal stack "Dialog" // see btn "Exit to top" of sub-stack "Dialog"
   end repeat
end mouseup

I'm sure there must be other/better ways of doing this but this is simple and it works; and you can take any number of actions depending on the value of the flag(s) set, and as custom props these are easily accessible even if the substack has been closed.

Stam

stam
Posts: 3060
Joined: Sun Jun 04, 2006 9:39 pm

Re: Exit to top?

Post by stam » Mon Aug 26, 2024 10:56 am

One additional comment: if using a custom prop as a flag, remember to reset it to it's default value (in this example you'd need to set the uStop of stack "dialog" to false either just before stopping the loop, or preferably when acting on the flag).

In otherwords, the "click me" button's script should look something like this:

Code: Select all

on mouseup
    put "" into fld "Test"
    repeat with i = 1 to 10
        put "Iteration" && i & cr after fld "Test"
        if (i = 5) then modal stack "Dialog"
        if the uStop of stack "dialog" then 
            set  the uStop of stack "dialog" to false
            exit to top
        end if
    end repeat
end mouseup

Zax
Posts: 519
Joined: Mon May 28, 2007 10:12 am
Contact:

Re: Exit to top?

Post by Zax » Mon Aug 26, 2024 11:22 am

Zax wrote:
Fri Aug 23, 2024 10:21 am
Of course, I could use the dialogData to test the clicked button but I thought that the "exit to top" command stopped all scripts.
There are several workarounds (I still believe that using the dialogData global property is the simplest).
"Exit" button script:

Code: Select all

on mouseUp
   set the dialogData to (the short name of me)
   close this stack
   put "   STOPPED BY EXIT TO TOP" & cr after fld "Test" of stack (the mainStack of this stack)
   exit to top -- !!!!!!!!!!!!!
end mouseUp
Button "Click me" of mainStack script:

Code: Select all

on mouseup
   put "" into fld "Test"
   repeat with i = 1 to 10
      put "Iteration" && i & cr after fld "Test"
      if (i = 5) then modal stack "Dialog" // see btn "Exit to top" of sub-stack "Dialog"
      if ("exit" is in the dialogData) then exit to top -- !!!!!!!!!!!!!!
   end repeat
end mouseup
The purpose of my post was to find out if I misunderstood the use of the Exit command, or if we can think that there is currently a bug with this command.

Post Reply