Handler works only if I add an answer statement

Deploying to Mac OS? Ask Mac OS specific questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Handler works only if I add an answer statement

Post by Mag » Wed May 21, 2014 2:06 pm

Hi all,

In a standalone app, I'm trying to handle the closeStackRequest statement to change some stack interface details before to close the stack I use as documents of the app. It seems that when I call a handler, it it has effect only when adding a answer statement at the end of it. Somebody know how to avoid to add an answer call and have it to work anyway?

Please let me know if this question is not clear, and I will try to explain a bit better :oops:

Here is an example of the structure I'm using:

Code: Select all

on closeStackRequest
   if the cAbc of this stack is not "ON" then
      doSomething
   else
      stopRun
   end if
   
   pass closeStackRequest
end closeStackRequest

Code: Select all

on stopRun
   if the abc of this stack is "ON" then
      send "stopMe" to button "start" of card "myCard"
      answer "Stopped" -- without this statement the above statement has not effect
   end if
end stopRun

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Handler works only if I add an answer statement

Post by Mark » Wed May 21, 2014 6:53 pm

Hi,

You set the cAbc of a stack but you check the contents of the abc of the stack. Maybe that's the reason why it doesn't work?

Usually, I use the closeStackRequest really only for checking conditions to determine if the stack can close. Everything else I put into the closeStack handler. That might work better.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: Handler works only if I add an answer statement

Post by Mag » Wed May 21, 2014 7:47 pm

Hi Mark,

Thank you for your replay.
Mark wrote:Usually, I use the closeStackRequest really only for checking conditions to determine if the stack can close. Everything else I put into the closeStack handler. That might work better.
Thank you for the advice, I will try to move the code there.

PS
Thank you for pointing the cAbc error, it was just a sort of pseudo code, in the real code I don't use it.

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: Handler works only if I add an answer statement

Post by Mag » Wed May 21, 2014 8:06 pm

OK, tested. It's the same. Handlers works only if I put an answer command on them. :roll:

Maybe without the answer command the stack is closed before they run, it seems that the answer command forces LC to complete the handler execution before to close the stack.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Handler works only if I add an answer statement

Post by Simon » Wed May 21, 2014 11:21 pm

Hi Mag,
One of the things the answer command does is stops the handler allowing the cpu to catch up.
I use a "wait 1 millisec with messages" when these types of errors occur. (wait 0 may work) Just replace your answer command with it.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: Handler works only if I add an answer statement

Post by Mag » Thu May 22, 2014 1:00 am

Thank you Simon, it worked!

Post Reply