stop a handler
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
stop a handler
I have a very simple button script:
on mouseUp
visual effect push right
go to card "menuCard"
end mouseUp
If I click it when a card script is running, an error dialogue is displayed. How can I send a message to the card to stop executing a handler? I have tried "exit to top" and deleting the pendingMessages.
on mouseUp
visual effect push right
go to card "menuCard"
end mouseUp
If I click it when a card script is running, an error dialogue is displayed. How can I send a message to the card to stop executing a handler? I have tried "exit to top" and deleting the pendingMessages.
Re: stop a handler
Hi chelling,
depends on the script that is running!
Could you please post (parts of) the script(s) in question?
Best
Klaus
depends on the script that is running!

Could you please post (parts of) the script(s) in question?
Best
Klaus
Re: stop a handler
One possible solution;
Set a flag when the card script begins. When the button is clicked, the flag can be checked to see if the card script is in progress - if so, then set an abort flag for the card script to pick up and stop whatever it's doing...
I'm guessing that the script is looping through something?
Set a flag when the card script begins. When the button is clicked, the flag can be checked to see if the card script is in progress - if so, then set an abort flag for the card script to pick up and stop whatever it's doing...
I'm guessing that the script is looping through something?
LiveCode Development & Training : http://splash21.com
Re: stop a handler
This is an app to teach 1st grade spelling. The error seems to be happening during a handler to move some buttons into place.
on dropLetters
sort lines of card field "startLocsField" of group "startLocsFieldGroup" by random(8000)
lock screen
put line 1 of card field "startLocsField" of group "startLocsFieldGroup" into tMove1
put line 2 of card field "startLocsField" of group "startLocsFieldGroup" into tMove2
put line 3 of card field "startLocsField" of group "startLocsFieldGroup" into tMove3
if tMove1 = "390,664" and tMove2 = "514,664" and tMove3 = "638,664" then
sort lines of card field "startLocsField" of group "startLocsFieldGroup" by random(8000)
put line 1 of card field "startLocsField" of group "startLocsFieldGroup" into tMove1
put line 2 of card field "startLocsField" of group "startLocsFieldGroup" into tMove2
put line 3 of card field "startLocsField" of group "startLocsFieldGroup" into tMove3
end if
unlock screen
if the environment is "mobile" then play specialFolderPath("engine") & "/audio/glassBreaking.mp3"
move button "spellLetter1" to tMove1
move button "spellLetter2" to tMove2
move button "spellLetter3" to tMove3
end dropLetters
I have seen "the flag" used before and I can tell that it is used as a custom property, but it confuses me! This is what I find in the dictionary ' "The flagged property of a field chunk specifies whether it is underlined with a red dotted line."
Thanks!
on dropLetters
sort lines of card field "startLocsField" of group "startLocsFieldGroup" by random(8000)
lock screen
put line 1 of card field "startLocsField" of group "startLocsFieldGroup" into tMove1
put line 2 of card field "startLocsField" of group "startLocsFieldGroup" into tMove2
put line 3 of card field "startLocsField" of group "startLocsFieldGroup" into tMove3
if tMove1 = "390,664" and tMove2 = "514,664" and tMove3 = "638,664" then
sort lines of card field "startLocsField" of group "startLocsFieldGroup" by random(8000)
put line 1 of card field "startLocsField" of group "startLocsFieldGroup" into tMove1
put line 2 of card field "startLocsField" of group "startLocsFieldGroup" into tMove2
put line 3 of card field "startLocsField" of group "startLocsFieldGroup" into tMove3
end if
unlock screen
if the environment is "mobile" then play specialFolderPath("engine") & "/audio/glassBreaking.mp3"
move button "spellLetter1" to tMove1
move button "spellLetter2" to tMove2
move button "spellLetter3" to tMove3
end dropLetters
I have seen "the flag" used before and I can tell that it is used as a custom property, but it confuses me! This is what I find in the dictionary ' "The flagged property of a field chunk specifies whether it is underlined with a red dotted line."
Thanks!
Re: stop a handler
Hi chelling,
AHA!
So you want to cancel the "move" of the "spellletters" buttons, right?
OK, you were close with "the pendingmessages", but you are not using SEND here,
so the pendingmessages is not of much help here.
Livecode keeps track of everything and does so for all currently moving controls -> the movingcontrols
Check the dictionary for more info.
Basically you need to "stop moving" all the objects in "the movingcontrols".
You can do this directly in the "Mouseup" handler, but since you may need this more than once in you stack
I would create a handler in the stackscript like this:
Now simply call this handler whenever neccessary:
Best
Klaus
P.S.
To set a "flag" only means that you should note something and store
this "note" in a custom property or maybe a gloabal variable for later access.
AHA!

So you want to cancel the "move" of the "spellletters" buttons, right?
OK, you were close with "the pendingmessages", but you are not using SEND here,
so the pendingmessages is not of much help here.
Livecode keeps track of everything and does so for all currently moving controls -> the movingcontrols
Check the dictionary for more info.
Basically you need to "stop moving" all the objects in "the movingcontrols".
You can do this directly in the "Mouseup" handler, but since you may need this more than once in you stack
I would create a handler in the stackscript like this:
Code: Select all
command stop_all_moving
put the movingcontrols into tMCs
repeat for each line tControl in tMCs
stop moving tControl
end repeat
end stop_all_moving
Code: Select all
on mouseUp
## First stop everything...
stop_all_moving
## THEN go to another card!
visual effect push right
go to card "menuCard"
end mouseUp
Klaus
P.S.
To set a "flag" only means that you should note something and store
this "note" in a custom property or maybe a gloabal variable for later access.
Re: stop a handler
No.
What was meant was to set a flag. This is an old, old programming term. Think about this infinite loop if there was no way to exit:
But in any case you have to have a way out of that repeat. Flags are generally custom properties, true, that are used to hold a value that can be checked in any of a number of ways to direct the action of some process. It is really a "flag". Waving or not, you can test its value and act accordingly. Here the "flag" was the variable "tFlag".
Craig Newman
What was meant was to set a flag. This is an old, old programming term. Think about this infinite loop if there was no way to exit:
Code: Select all
on mouseUp
put "444" into tFlag
repeat forever
put random(999) into temp
put temp into msg
wait 2
if the optionKey is down then exit repeat --one way out. You may need it if you just run this handler
--if the mouseClick then exit repeat --another option
--if temp = tflag then exit repeat --another option. and might be what we call using a flag. This will happen after some length of time.
end repeat
end mouseUp
Craig Newman
Re: stop a handler
Thanks everyone. Klaus thanks for the movingcontrols tip! I added the "command stop_all_moving" first to the button that takes the user back to the menu card, and then added a close card handler in the stack script. In the Livecode IDE, it's still throwing the error - specifically to the buttons moving into place in the "dropLetters" handler. It does not throw an error in the iOS simulator or on an iPad 3. Should I be concerned?
If I set a flag will that be a stack custom property that I set to be either true or false? If I need to do that, I will have to add it to the menu card navigation button and the "dropLetters" handler on each of the cards, right? I am thinking each openCard it's set to false, at the start of the "dropLetters" handler it gets set to true and then the menu button that takes the user back to the menu card checks to see if it is true. If I do this, will it stop the dropLetters" handler even though "command stop_all_moving" didn't?
IF it's not causing a problem in the simulator or on an iPad do I need to do that? The the button that takes the user back to the menu card is a group, so that's not a big deal. Adding it to each card will take some time. If It needs to be done though I want to do it.
Thanks again!
Celeste
If I set a flag will that be a stack custom property that I set to be either true or false? If I need to do that, I will have to add it to the menu card navigation button and the "dropLetters" handler on each of the cards, right? I am thinking each openCard it's set to false, at the start of the "dropLetters" handler it gets set to true and then the menu button that takes the user back to the menu card checks to see if it is true. If I do this, will it stop the dropLetters" handler even though "command stop_all_moving" didn't?
IF it's not causing a problem in the simulator or on an iPad do I need to do that? The the button that takes the user back to the menu card is a group, so that's not a big deal. Adding it to each card will take some time. If It needs to be done though I want to do it.
Thanks again!
Celeste
Re: stop a handler
Hi Celeste (what a beautiful name!)
what error does the IDE throw? When exactly does it pop up?
I am sure we can fix it!
In a standalone (desktop or mobile) there will no error be shown UNLESS you programmed this!
Remember: a standalone = Livecode MINUS the IDE!
The IDE catches and shows/throws errors, in a standalone the script will simply halt at this point!
Best
Klaus
what error does the IDE throw? When exactly does it pop up?
I am sure we can fix it!

In a standalone (desktop or mobile) there will no error be shown UNLESS you programmed this!
Remember: a standalone = Livecode MINUS the IDE!
The IDE catches and shows/throws errors, in a standalone the script will simply halt at this point!
Best
Klaus
Re: stop a handler
Thanks Klaus. My name is German
This is a typical error message. In this instance, I was on a card that was dropping the letters (buttons) that spell the word "duck". The error message displayed on"menuCard".
card "duck card": execution error at line 42 (Chunk: no such object) near "spellLetter3", char 1

This is a typical error message. In this instance, I was on a card that was dropping the letters (buttons) that spell the word "duck". The error message displayed on"menuCard".
card "duck card": execution error at line 42 (Chunk: no such object) near "spellLetter3", char 1
Re: stop a handler
Hallo Celeste,
Actually this is latin and means "die Himmlische"
OK, the probem is that these 3 buttons move one after another so one of two of them may
not be moving YET when you fire the "stop_all_moving" command.
Maybe you just want to DISABLE that "go cd xyz" button until all letters are in place?
Might also be a good pedagocial procedure
Best
Klaus
Not Celeste?chelling wrote:Thanks Klaus. My name is German

Actually this is latin and means "die Himmlische"

Ah, now i get it!chelling wrote:This is a typical error message. In this instance, I was on a card that was dropping the letters (buttons) that spell the word "duck". The error message displayed on"menuCard".
card "duck card": execution error at line 42 (Chunk: no such object) near "spellLetter3", char 1
OK, the probem is that these 3 buttons move one after another so one of two of them may
not be moving YET when you fire the "stop_all_moving" command.
Maybe you just want to DISABLE that "go cd xyz" button until all letters are in place?
Might also be a good pedagocial procedure

Code: Select all
on dropLetters
## DISABLE at the top of the script:
DISABLE btn " the one that causes grief..."
sort lines of card field "startLocsField" of group "startLocsFieldGroup" by random(8000)
lock screen
put line 1 of card field "startLocsField" of group "startLocsFieldGroup" into tMove1
put line 2 of card field "startLocsField" of group "startLocsFieldGroup" into tMove2
put line 3 of card field "startLocsField" of group "startLocsFieldGroup" into tMove3
if tMove1 = "390,664" and tMove2 = "514,664" and tMove3 = "638,664" then
sort lines of card field "startLocsField" of group "startLocsFieldGroup" by random(8000)
put line 1 of card field "startLocsField" of group "startLocsFieldGroup" into tMove1
put line 2 of card field "startLocsField" of group "startLocsFieldGroup" into tMove2
put line 3 of card field "startLocsField" of group "startLocsFieldGroup" into tMove3
end if
unlock screen
if the environment is "mobile" then
play specialFolderPath("engine") & "/audio/glassBreaking.mp3"
end if
move button "spellLetter1" to tMove1
move button "spellLetter2" to tMove2
move button "spellLetter3" to tMove3
## Now everything is in place, ENABLE the button again
ENABLE btn " the one that causes grief..."
end dropLetters
Klaus
Re: stop a handler
Thanks Klaus! That's what I ended up doing. I really appreciate your help.