Page 2 of 3

Re: Exit to top?

Posted: Sun Aug 25, 2024 12:54 am
by richmond62
What's a 'Brit'?

Re: Exit to top?

Posted: Sun Aug 25, 2024 2:16 am
by jacque
richmond62 wrote: Sun Aug 25, 2024 12:54 am What's a 'Brit'?
A US cultural expression.

Re: Exit to top?

Posted: Sun Aug 25, 2024 3:57 am
by dunbarx
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

Re: Exit to top?

Posted: Sun Aug 25, 2024 6:48 am
by jacque
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."

Re: Exit to top?

Posted: Sun Aug 25, 2024 11:48 am
by Zax
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 1235 times

Re: Exit to top?

Posted: Sun Aug 25, 2024 12:40 pm
by richmond62
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)

Re: Exit to top?

Posted: Sun Aug 25, 2024 2:56 pm
by AndyP
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?

Re: Exit to top?

Posted: Sun Aug 25, 2024 5:23 pm
by richmond62
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.

Re: Exit to top?

Posted: Sun Aug 25, 2024 6:51 pm
by dunbarx
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

Re: Exit to top?

Posted: Sun Aug 25, 2024 6:59 pm
by jacque
@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.

Re: Exit to top?

Posted: Sun Aug 25, 2024 7:03 pm
by richmond62
So, the problem lies with using a modal stack.

Re: Exit to top?

Posted: Mon Aug 26, 2024 7:19 am
by Zax
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.

Re: Exit to top?

Posted: Mon Aug 26, 2024 9:33 am
by stam
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

Re: Exit to top?

Posted: Mon Aug 26, 2024 10:56 am
by stam
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

Re: Exit to top?

Posted: Mon Aug 26, 2024 11:22 am
by Zax
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.