Page 1 of 1

Stopping an object script containing wait

Posted: Sat Jan 26, 2013 1:37 am
by cusingerBUSCw5N
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!

Re: Stopping an object script containing wait

Posted: Sat Jan 26, 2013 2:19 am
by Simon
At the bottom of the script for the Cancel button add
"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
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

Re: Stopping an object script containing wait

Posted: Sat Jan 26, 2013 5:09 am
by dunbarx
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

Re: Stopping an object script containing wait

Posted: Sat Jan 26, 2013 8:22 am
by cusingerBUSCw5N
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

Re: Stopping an object script containing wait

Posted: Sat Jan 26, 2013 6:23 pm
by dunbarx
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

Re: Stopping an object script containing wait

Posted: Sat Jan 26, 2013 10:30 pm
by magice
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 :

Code: Select all

 do something
wait for 2 seconds
do Something Else 
write it like this

Code: Select all

do something
send doSomethingElse to me in 2 seconds

on doSomethingElse
do something else
end doSomethingElse


Re: Stopping an object script containing wait

Posted: Sun Jan 27, 2013 3:16 am
by cusingerBUSCw5N
got it. Thanks