Page 1 of 1

Handler works only if I add an answer statement

Posted: Wed May 21, 2014 2:06 pm
by Mag
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

Re: Handler works only if I add an answer statement

Posted: Wed May 21, 2014 6:53 pm
by Mark
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

Re: Handler works only if I add an answer statement

Posted: Wed May 21, 2014 7:47 pm
by Mag
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.

Re: Handler works only if I add an answer statement

Posted: Wed May 21, 2014 8:06 pm
by Mag
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.

Re: Handler works only if I add an answer statement

Posted: Wed May 21, 2014 11:21 pm
by Simon
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

Re: Handler works only if I add an answer statement

Posted: Thu May 22, 2014 1:00 am
by Mag
Thank you Simon, it worked!