Stopping an object script containing wait

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
cusingerBUSCw5N
Posts: 339
Joined: Wed Jul 11, 2012 9:24 pm

Stopping an object script containing wait

Post by cusingerBUSCw5N » Sat Jan 26, 2013 1:37 am

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!

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Stopping an object script containing wait

Post by Simon » Sat Jan 26, 2013 2:19 am

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

dunbarx
VIP Livecode Opensource Backer
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

Post by dunbarx » Sat Jan 26, 2013 5:09 am

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

cusingerBUSCw5N
Posts: 339
Joined: Wed Jul 11, 2012 9:24 pm

Re: Stopping an object script containing wait

Post by cusingerBUSCw5N » Sat Jan 26, 2013 8:22 am

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

dunbarx
VIP Livecode Opensource Backer
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

Post by dunbarx » Sat Jan 26, 2013 6:23 pm

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

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: Stopping an object script containing wait

Post by magice » Sat Jan 26, 2013 10:30 pm

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


cusingerBUSCw5N
Posts: 339
Joined: Wed Jul 11, 2012 9:24 pm

Re: Stopping an object script containing wait

Post by cusingerBUSCw5N » Sun Jan 27, 2013 3:16 am

got it. Thanks

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”