Page 1 of 1
Cancelling pending messages...
Posted: Wed Feb 13, 2013 3:58 am
by paulsr
Greetings:
Maybe there's something I haven't understood about cancelling pending messages when a card stops executing.
If I put...
Code: Select all
on closeCard
repeat until the pendingMessages is empty
cancel item 1 of line 1 of the pendingMessages
end repeat
end closeCard
...shouldn't that stop any handlers that are executing, before the next card executes?
I'm having a problem where I randomly get an execution error on switching cards ... maybe 1 time in 10. The line nbr in the error message is in a handler which should have stopped executing.
In the repeating handler I have something like...
Code: Select all
if "someRoutine" is not in the pendingmessages then
send "someRoutine" to me in 10 seconds
end if
Is there something else I need to do?
Many thanks...
--paul
Re: Cancelling pending messages...
Posted: Wed Feb 13, 2013 5:54 am
by dunbarx
I use this now and then, and have not played with a set up to test what you are dealing with, but why are you canceling only the first item of each line of the pendingMessages? Each line has four components, an ID, a message, a destination and so forth. Does it help that part of your query if you just cancel the line itself? That is normal practice.
As for the other thing, what is the error message? It seems OK to check if a message is pending before sending it again, though I bet there are simpler ways to do what you need. But what does LC complain about?
Craig Newman
Re: Cancelling pending messages...
Posted: Wed Feb 13, 2013 7:05 am
by shaosean
paulsr wrote:...shouldn't that stop any handlers that are executing, before the next card executes?
Nope.. Any handlers that are executing will keep running.. "pending" means they are waiting to run.. If you want to stop currently running handlers you need to "exit to top" but that stops everything (including the repeat loop)..
Re: Cancelling pending messages...
Posted: Wed Feb 13, 2013 7:46 am
by paulsr
Thanks for your reply Craig...
You asked why I am cancelling only the first item of each line ... because when I don't fully understand something I hunt around for code and examples.
On this page -
http://revolution.byu.edu/time/timeDelay.php - there is an example at the bottom, which shows "cancel item 1 of line 1 of the pendingMessages". Since item 1 contains the ID, I assumed that was what I needed to use in order to cancel something.
And "cancel line 1 of the pendingMessages" gives me an error.
As for the error I'm seeing... "Execution Error. An error occurred on line: 879."
Line 879 is on the card I have just left, and is trying to put something onto screen. So, I think the error is valid and leads me to conclude a handler is still running, when it shouldn't be.
But; now that I've played around some more, I realize I can only make this happen on my iPad, and not on my PC. Maybe this is an iOS problem, and I've posted my msg in the wrong part of the forum.
--paul
Re: Cancelling pending messages...
Posted: Wed Feb 13, 2013 7:48 am
by paulsr
shaosean wrote:paulsr wrote:...shouldn't that stop any handlers that are executing, before the next card executes?
Nope.. Any handlers that are executing will keep running.. "pending" means they are waiting to run.. If you want to stop currently running handlers you need to "exit to top" but that stops everything (including the repeat loop)..
Thanks ... Could you give me an example please ... where do I put the "exit to top"? In the closeCard handler?
--paul
Re: Cancelling pending messages...
Posted: Wed Feb 13, 2013 8:02 am
by paulsr
Hmm... I'm not sure "exit to top" is the solution.
What I need is a way to stop any executing handlers when the card stops executing. Is there some way to do this?
Or, should they stop automatically when the card stops?
TIA
--paul
Re: Cancelling pending messages...
Posted: Wed Feb 13, 2013 11:49 am
by shaosean
When a handler starts, it only stops when it reaches the 'end' of it, or you force out with the 'exit to top'.. The pendingMessages is to see the handlers that are to be run after the current handler is done.. The cancel command is only used to cancel those pending messages..
Re: Cancelling pending messages...
Posted: Thu Feb 14, 2013 12:07 am
by Simon
Hi Paul,
Is there anyway you can re-write this code?
Code: Select all
if "someRoutine" is not in the pendingmessages then
send "someRoutine" to me in 10 seconds
end if
As you can see it is in direct conflict to your "cancel pendingMessages" and if triggered will start the message again.
You could probably use just "send "someRoutine" to me in 10 seconds" and get rid of the if-then.
Simon
Re: Cancelling pending messages...
Posted: Thu Feb 14, 2013 4:09 am
by paulsr
Hi Simon,
I can't see how your suggestion would help. The check of pendingmessages is just to prevent me restarting the handler more than once. If it's already queued, then I don't need to start it.
What I need to do is stop it when the card ends. Maybe I need to send it a signal, via a custom property or something. Or as shaosean suggests, by using "exit to top" ... but I haven't yet figured where to put this.
Thanks...
--paul
Re: Cancelling pending messages...
Posted: Thu Feb 14, 2013 4:20 am
by Simon
Hi Paul,
My point was when you cancel the pendingMessages your if-then restarts it.
As in your if-then will answer true, right after you cancel it and so start it right back up.
Simon
Re: Cancelling pending messages...
Posted: Thu Feb 14, 2013 5:05 am
by paulsr
I must need more coffee Simon!
Your solution works fine ... many thanks. But I can't figure why.
--paul
Re: Cancelling pending messages...
Posted: Thu Feb 14, 2013 6:22 am
by Simon
Glad it's working for you.
I'm not even sure where your if-then code is. The random occurrence may point to it.
Simon