Why is the ShutdownRequest message called twice

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

Post Reply
Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Why is the ShutdownRequest message called twice

Post by Simon Knight » Tue Nov 18, 2014 7:06 pm

Hi,

I have a splash stack that loads my main stack. The main stack uses a revbrowserObject and also has a sub stack. I wish to save the present state when the main stack closes so have added a button that issues the quit command. I have added the following handler :
on shutdownRequest
answer question "Are you sure you want to quit?" with "Yes" or "No"
if it is "Yes" then
Save stack "PDF_Rename"
pass shutdownRequest
end if
end shutdownRequest
If the handler is put in the card it works as I expect but if it is put in the stack then it is being called twice. I have created an empty stack and sub stack and the routine is only called once when it is in the stack. Can anyone explain what might be happening to the message path.

Also is the shutdown message a synonym of shutdownRequest ? The dictionary does not list synonyms for either message but they perform the same action :
ShutdownRequest : Sent to the current card of the defaultStack when the user tries to quit the application.
Shutdown : Sent to the current card of the defaultStack when the application is quitting.
Does this mean that the ShutdownRequest will generate a Shutdown message but not the other way around?
best wishes
Skids

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Why is the ShutdownRequest message called twice

Post by FourthWorld » Tue Nov 18, 2014 7:53 pm

If the handler is defined in the mainstack it'll inherit all messages passed to it from substacks.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Re: Why is the ShutdownRequest message called twice

Post by Simon Knight » Tue Nov 18, 2014 9:42 pm

Ok, but in this case the card with the quit button is the only card of the main stack so I think that the message should be offered to the card first then the main stack and then up to the engine. I wonder if this is a feature of testing in the IDE ?
best wishes
Skids

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Why is the ShutdownRequest message called twice

Post by FourthWorld » Tue Nov 18, 2014 9:59 pm

Does the behavior differ in the standalone?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Re: Why is the ShutdownRequest message called twice

Post by Simon Knight » Wed Nov 19, 2014 9:05 am

I have just tried it and the standalone is the same as the IDE. I will put it down to just one of those things that happen.
best wishes
Skids

Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Re: Why is the ShutdownRequest message called twice

Post by Simon Knight » Wed Nov 19, 2014 11:16 am

Grrrr !

The dictionary hints that the shutdownRequest may be a little tricky and recommends placing the handler in a library stack or back script. I have tried placing the following code in many places :

Code: Select all

on shutdownRequest
   Save  stack "PDF_Rename"
   answer question "Are you sure you want to quit?" with "Yes" or "No"
   if it is "Yes" then 
      pass shutdownRequest 
   end if
end shutdownRequest
Splash stack that load the app - handler is not found by the app as the splash is closed - I expected this but include it in the process of elimination.
In Library Stack - Still called more than once
In the stack - Called more than once
In the Card - Called more than once

My latest build has the handler in the card script and it is called only once but for some reason the Save command has stopped working. I have no idea what is happening but I have a feeling that the Save command is interfering with the message path in some way.
best wishes
Skids

Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Re: Why is the ShutdownRequest message called twice

Post by Simon Knight » Wed Nov 19, 2014 12:28 pm

I decided to follow the dictionary and add the handler to a library stack as I thought I had before. Now it gets called once which is good however the save stack is failing when called in the standalone.

I will post another question on the Mac OS board ref the file save problem.
best wishes
Skids

Post Reply