Stopping an object script containing wait
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 339
- Joined: Wed Jul 11, 2012 9:24 pm
Stopping an object script containing wait
I have an object script that uses wait 1 seconds - to turn on and off various fields and buttons - (to create a presentation). If someone clicks a cancel button (which does NOT send someone to another card) - the script continues to run. Is there anything that I can put in the cancel button script that could stop the original script from continuing?
Thanks!
Thanks!
-
- VIP Livecode Opensource Backer
- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
- Location: Palo Alto
Re: Stopping an object script containing wait
At the bottom of the script for the Cancel button add
"exit to top"
I have a card with to buttons on it
Pressing the first one will sound a beep after 2 secs. If I hit btn 1 then immediately hit btn 2 there is no beep.
You may want to look at waitDepth in the dictionary as well.
Simon
"exit to top"
I have a card with to buttons on it
Code: Select all
on mouseUp
wait 2 seconds with messages
beep
end mouseUp
on mouseUp
exit to top
end mouseUp
You may want to look at waitDepth in the dictionary as well.
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
-
- VIP Livecode Opensource Backer
- Posts: 9670
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Stopping an object script containing wait
What Simon said.
It is important to know that the "wait" command is blocking, unless you include "with messages". It is sort of like a modal dialog; you have to dismiss it, or wait until it times out before control is returned to the user. I grew up with "wait", and without that option.
When you feel up to it, try to rewrite your script using the "send" command, in its "in time" variant. This is a wonderful tool. Practice with it.
Craig Newman
It is important to know that the "wait" command is blocking, unless you include "with messages". It is sort of like a modal dialog; you have to dismiss it, or wait until it times out before control is returned to the user. I grew up with "wait", and without that option.
When you feel up to it, try to rewrite your script using the "send" command, in its "in time" variant. This is a wonderful tool. Practice with it.
Craig Newman
-
- Posts: 339
- Joined: Wed Jul 11, 2012 9:24 pm
Re: Stopping an object script containing wait
Cool. Adding "exit to top" worked great. I also added "with messages" to my wait code.
Can you explain again why the send command is better than the wait command? Thanks
Can you explain again why the send command is better than the wait command? Thanks
-
- VIP Livecode Opensource Backer
- Posts: 9670
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Stopping an object script containing wait
The two commands have different uses. I just wanted you to know about "send".
"Wait" has specific features in that it can detect user events. For example, "wait until the commandKey is down". The command is still blocking, but with one special event that it keeps its sights on. Blocking has its uses, of course.
In general, the "send in time" is more flexible, and frequently solves issues that arise when multiple processes are going on. Timers, for example, that run alongside other script actions, can be managed in the background, so to speak, while a script is running. You send a message after a specified interval, frequently in a repeat loop so the message is sent repeatedly, or perhaps called repeatedly by the main handler, running in conjunction with other stuff. The messages are queued by the engine, and therefore do not have a life of their own like "wait" does.
You will appreciate this one day when you need it, and you will know when the time comes. I simply wanted you to experiment a little with that methodology.
Craig Newman
"Wait" has specific features in that it can detect user events. For example, "wait until the commandKey is down". The command is still blocking, but with one special event that it keeps its sights on. Blocking has its uses, of course.
In general, the "send in time" is more flexible, and frequently solves issues that arise when multiple processes are going on. Timers, for example, that run alongside other script actions, can be managed in the background, so to speak, while a script is running. You send a message after a specified interval, frequently in a repeat loop so the message is sent repeatedly, or perhaps called repeatedly by the main handler, running in conjunction with other stuff. The messages are queued by the engine, and therefore do not have a life of their own like "wait" does.
You will appreciate this one day when you need it, and you will know when the time comes. I simply wanted you to experiment a little with that methodology.
Craig Newman
Re: Stopping an object script containing wait
Do what Craig said. Using wait for timing will lock up the computer because it is tying up the processor and the computer can't execute any more commands even for other apps that are running. So instead of :
write it like this
Code: Select all
do something
wait for 2 seconds
do Something Else
Code: Select all
do something
send doSomethingElse to me in 2 seconds
on doSomethingElse
do something else
end doSomethingElse
-
- Posts: 339
- Joined: Wed Jul 11, 2012 9:24 pm
Re: Stopping an object script containing wait
got it. Thanks