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

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

Exit to top?

Post by Zax » Fri Aug 23, 2024 10:21 am

Hello,

I have a substack that serves as a modal dialog. I call it with script like:

Code: Select all

modal stack "mySubstack"
put " Dialog closed!" after msg
This substack displays an "Exit" button whose script is:

Code: Select all

on mouseUp
   close this stack
   put "Closing dialog..."
   exit to top
end mouseUp
The problem is that if I click on the "Exit" button of the substack in modal mode, the rest of the calling code is executed (the msg box contains "Closing dialog... Dialog closed!").
Of course, I could use the dialogData to test the clicked button but I thought that the "exit to top" command stopped all scripts.

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 » Fri Aug 23, 2024 2:23 pm

So did I.

The dictionary is very clear that execution halts, along with any and all pending messages, including if the current handler was called from afar, any pending messages in the calling handler.

Craig

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

Re: Exit to top?

Post by stam » Fri Aug 23, 2024 6:39 pm

Zax wrote:
Fri Aug 23, 2024 10:21 am
The problem is that if I click on the "Exit" button of the substack in modal mode, the rest of the calling code is executed (the msg box contains "Closing dialog... Dialog closed!").
Of course, I could use the dialogData to test the clicked button but I thought that the "exit to top" command stopped all scripts.
I suspect that if you close rather than hide, the code execution stops but not sure. You can set a breakpoint and stop through the code to confirm.
However if hiding, the tricky bit might be that exit to top will stop all code, so any subsequent code to actually close the substack probably won't fire.

You may find these handlers helpful (from my accumulated toolbox, I'm sure I borrowed this form somewhere, but now can't remember who to thank):

Code: Select all

## stop a specific pending message
on stopPendingMessage pMessage
   repeat for each line tLine in the pendingmessages
      if pMessage is in item 1 of tLine then
         cancel item 1 of tLine
      end if
   end repeat
end stopPendingMessage

Code: Select all

## stop all pending messages
on stopAllPending 
   repeat for each line tLine in the pendingmessages
      cancel item 1 of tLine
   end repeat
end stopAllPending
The former may be helpful if you intend to stop specific handlers - you can do that and then just close the substack. The latter may be helpful assuming that it won't cancel a handler in progress, but can't say that for sure.
Alternatively: consider using closeStackReqeust, or assigning a behavior so you can use the after closeStack handler. Or send in time.

S.

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

Re: Exit to top?

Post by Zax » Sat Aug 24, 2024 7:55 am

Thank you for your answers Stam.

For pending messages, I wouldn't really know which one(s) to delete:

Code: Select all

6003,1724478869.547847,ideMessageSendWithParameters,stack "/Applications/LiveCode 9.6.13.app/Contents/Tools/Toolset/libraries/revidelibrary.8.livecodescript"
6004,1724478869.558268,revUpdateScriptEdit,stack "/Applications/LiveCode 9.6.13.app/Contents/Tools/Toolset/libraries/revfrontscriptlibrary.livecodescript"
6009,1724478869.572254,ideMessageSend,stack "/Applications/LiveCode 9.6.13.app/Contents/Tools/Toolset/libraries/revidelibrary.8.livecodescript"
6005,1724478869.648272,revCloseUpdate,stack "/Applications/LiveCode 9.6.13.app/Contents/Tools/Toolset/libraries/revfrontscriptlibrary.livecodescript"
6008,1724478869.8721,__DoUpdateIntelligenceDisplay,stack "/Applications/LiveCode 9.6.13.app/Contents/Tools/Toolset/palettes/message-box/revmessagebox.8.rev"
6010,1724478869.974214,revUpdateSelectionChanged,stack "/Applications/LiveCode 9.6.13.app/Contents/Tools/Toolset/libraries/revbackscriptlibrary.livecodescript"
6006,1724478870.549168,revCheckStackOpen,stack "/Applications/LiveCode 9.6.13.app/Contents/Tools/Toolset/libraries/revfrontscriptlibrary.livecodescript"
5638,1724478890.054865,__revInternal_SavePreferences,stack "/Applications/LiveCode 9.6.13.app/Contents/Tools/Toolset/home.livecodescript"
Trapping closeStack and closeStackRequest doesn't change anything: the script calling the modal dialog always continues.
Concerning the use of a behavior, I wouldn't really know how to use it in this specific case.
Finally, the use of send in time seems risky to me: what delay to use?

It doesn't matter in this case if the Exit command doesn't work as expected, I'll use the dialogData.

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

Re: Exit to top?

Post by richmond62 » Sat Aug 24, 2024 9:37 am

How about NOT using Exit to top?

How about making sùre that the destroyStack of your dialog substack is set to true, and then issuing a close stack command?

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

Re: Exit to top?

Post by stam » Sat Aug 24, 2024 10:42 am

You could set a global flag in the calling handler, the one that continues, for it to exit to top if the flag is true, and just set that flag on closing stack.

As for using a behaviour, you could set the behaviour of the substack to the script of a button, either in the PI or in script. This button’s script only needs this:

Code: Select all

after closeStack
    Exit to top
End closeStack 


If you’re still stuck, please post a very simplified example of your issue and you’ll probably get at least 3 different solution ;)

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

Re: Exit to top?

Post by Zax » Sat Aug 24, 2024 11:33 am

@richmond62: the substack's destroyStack is already set to true, but that's not the problem. The problem is that the "exit to top" command should stop *all* running scripts. As far as I know, all programming languages ​​have an exit or die command.

@stam: the global dialogData property is a good replacement for a global variable in this specific case.
I understand the trick of using a behavior better, but it wouldn't work in my case, because I don't want to stop scripts in all cases where the substack is closed. Anyway, thanks for the explanation.

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

Re: Exit to top?

Post by stam » Sat Aug 24, 2024 2:10 pm

Zax wrote:
Sat Aug 24, 2024 11:33 am
@stam: the global dialogData property is a good replacement for a global variable in this specific case.
I understand the trick of using a behavior better, but it wouldn't work in my case, because I don't want to stop scripts in all cases where the substack is closed. Anyway, thanks for the explanation.
erm... I only used "exit to top" because you specifically added this to your own script. You mention nothing about conditional actions, but that is easy to cater for.
You could instead

Code: Select all

if <condition> then send exit "<handler name>" to "<container>"
There are many ways to achieve the same goal - whatever works best for you...

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 » Sat Aug 24, 2024 2:15 pm

Richmond.
How about NOT using Exit to top?
The ability to shut all activity down completely, period, full stop, with a single trusted command, is very comforting to me. One is left alone with one's project, happily idling away.

Closing a stack, with whatever destructiveness and collateral damage, just don't hunt.

Craig

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

Re: Exit to top?

Post by richmond62 » Sat Aug 24, 2024 2:18 pm

just don't hunt
?

Do you mean "it won't do the trick" ?
Last edited by richmond62 on Sat Aug 24, 2024 2:25 pm, edited 1 time in total.

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

Re: Exit to top?

Post by stam » Sat Aug 24, 2024 2:24 pm

Rather than endless speculation, if @Zax hasn't solved this I'd suggest posting a test stack demonstrates the issue.
Solutions would probably arrive within a few hours, if not minutes.

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 » Sat Aug 24, 2024 6:37 pm

Code: Select all

## stop a specific pending message
on stopPendingMessage pMessage
   repeat for each line tLine in the pendingmessages
      if pMessage is in item 1 of tLine then
         cancel item 1 of tLine
      end if
   end repeat
end stopPendingMessage
Unless you know the message ID, this won't work. The handler name is item 3. I usually do this:

Code: Select all

if tLine contains pMessage then 
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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 » Sat Aug 24, 2024 6:42 pm

richmond62 wrote:
Sat Aug 24, 2024 2:18 pm
just don't hunt
?

Do you mean "it won't do the trick" ?
Yes. Craig used an abbreviated version of "that dog won't hunt" implying that the dog is useless. I think you have to be from the southern states of the US to make the connection, which neither Craig nor I are from, but we are multicultural.
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 » Sat Aug 24, 2024 6:53 pm

but we are multicultural
If that means multicultural only re cultures inwith the USA that is a fairly narrow definition of multicultural.

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 » Sat Aug 24, 2024 9:20 pm

richmond62 wrote:
Sat Aug 24, 2024 6:53 pm
but we are multicultural
If that means multicultural only re cultures inwith the USA that is a fairly narrow definition of multicultural.
I was being a bit tongue-in-cheek, but if you lived here you'd know that the north and south are very different in many respects. In general it truly does have different cultures, different values, and different life experiences. That's a generalization of course, the big cities tend to be more liberal and there are certainly northern states that are conservative. But if I understand it correctly, northerners sometimes refer to the south the same way Brits refer to Wales. As Heather says though, "it's a country!" :)

The US is very very huge. There are subcultures in pockets all over the place, including lots of immigrants from all over the world from whom I learned quite a bit from those who migrated here. I learned their stories and have been invited to their ceremonies. In a larger city with a lot of immigrants, you don't necessarily need to travel to enjoy other cultures and traditions.

Anyway...it was a joke.

PS: Somali wedding attire is gorgeous! And they have a women's coffee ceremony daily; no men allowed.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply