Page 1 of 1
Stopping a "run away train"
Posted: Sun Aug 29, 2010 1:27 am
by urbaud
I have been experimenting with various Rev commands as part of my learning and today I was experimenting with the rectangle property and developed the following code. It displays a label with text (no border) moving across the stack window. My problem is I can’t figure out a way to use the mouse to stop it. At the moment I have to use Command + . to stop it.
I have tried:
if the mouseClick is true then exit repeat - doesn’t work
If the mouseClick is true then exit mouseUp - doesn’t work
Even tried setting the wait command to 0 with another button, with no luck. Any suggestions?
Code: Select all
Global milsec
on mouseUp
put 1 into milsec
repeat with i = -10 to 600 --the 600 is the width of the stack window
repeat with t = -10 to 600
set the rectangle of fld "t3" to i,100,t,125
Wait milsec millisecond with messages
end repeat
end repeat
end mouseUp
Re: Stopping a "run away train"
Posted: Sun Aug 29, 2010 2:17 am
by mwieder
Right - you do *not* want that repeat loop inside your mouseup handler. Try something like the following (untested): that will let the mouseUp handler finish before starting the repeat loops. Otherwise the fact that you're still in a mouseUp handler will block any further mouse commands until it's done.
Code: Select all
on mouseUp
send "DisplayTheMessage" to me in 0 milliseconds
end mouseUp
on DisplayTheMessage
repeat with i = -10 to 600
repeat with t= -10 to 600
set the rectangle of fld "t3" to i,100,t,125
if the mouse is down then
exit DisplayTheMessage
end if
end repeat
end repeat
end DisplayTheMessage
Re: Stopping a "run away train"
Posted: Sun Aug 29, 2010 6:52 am
by urbaud
Hi mwieder,
Thanks for your suggested script. I tried it, but it didn't work. What I did was place it in a new button. When I clicked on the button, it would stop momentarily, but as soon as I let up the mouse button it started again. So, I placed another button and inserted the following code. Clicking on this new button stopped it. So, thanks for the help.
Code: Select all
on mouseUp
put 0 into i
put 0 into t
end mouseUp
Re: Stopping a "run away train"
Posted: Sun Aug 29, 2010 9:14 am
by Regulae
Hi urbaud,
This works in a button script:
Code: Select all
global repeatEnable
on mouseUp
if repeatEnable = "yes" then
put "no" into repeatEnable
pass mouseUp
end if
if repeatEnable <> "yes" then
send "DisplayTheMessage" to me in 0 milliseconds
put "yes" into repeatEnable
end if
end mouseUp
on DisplayTheMessage
repeat with i = -10 to 600
repeat with t= -10 to 600
set the rectangle of fld "t3" to i,100,t,125
if the mouse is down then
exit DisplayTheMessage
end if
end repeat
end repeat
end DisplayTheMessage
Regards,
Michael
Re: Stopping a "run away train"
Posted: Sun Aug 29, 2010 10:18 am
by Janschenkel
A while back I wrote up a blog post about the 'wait' command to improve the user experience in tight loops:
But the waiting makes me curious
HTH,
Jan Schenkel.
Re: Stopping a "run away train"
Posted: Sun Aug 29, 2010 9:42 pm
by urbaud
Hi Michael and Jan,
Thanks for your suggestions. It's amazing how quickly the Rev developer community comes to the aid of a fellow "developer", albeit a beginner and hobbyist only. As one of the other developers said in another posting, "You can do the same function in Rev in several different ways" (I'm paraphrasing). Your suggestions are the first time I've seen a "on mouseUp" handler "influence" another handler i.e. the "on DisplayTheMessage", or perhaps it's the other way around, the "on DisplayTheMessage" function is "influencing" the "on mouseUp" handler. .
Just a question about custom functions. Am I correct in assuming that the "on DisplayTheMessage" handler is in fact a custom function? If that's correct, then mwieder could have called it anything he wanted, correct? or is the "onDisplayTheMessage" function built into Rev?
Dan
Re: Stopping a "run away train"
Posted: Sun Aug 29, 2010 11:25 pm
by mwieder
I could indeed have called it anything (and did).
Well, I warned you it was untested, and sure enough I forgot to put in a semaphore to flag the fact that we were already looping. And Michael fixed that one up. And your method of setting the two global variables from a second button obviously also works. It's a bit of a brute force method to my way of thinking, but as you mentioned, there are any number of ways to handle any given problem.
Check out Jan's writeup if you haven't yet.