Page 1 of 1

Button trick?

Posted: Fri Aug 15, 2008 7:59 am
by bjb007
I want to have a button which I can set
to "Auto On" and "Auto Off" to run a script
automatically if the user wishes.

So need a way to get out of a repeat loop
when the label of the button is "Auto On"
and is clicked.

Have so far this - which of course doesn't
exit the loop.

Code: Select all

on mouseUp
  if the label of me is "Auto Off" then
   set the label of me to "Auto On"
  end if
  
  if the label of me is "Auto On" then
  repeat while label of me is "Auto On"
    send "mouseUp" to button btnNextNumber
    wait 1 sec
  end repeat
  end if  
end mouseUp
This, of course, goes on for ever which
isn't what I want.

Expect it's something to do with messages
which I know nothing about - yet.

Posted: Fri Aug 15, 2008 9:04 am
by SparkOut
try

Code: Select all

wait 1 sec with messages
in the loop, otherwise the wait command blocks any messages to be able to handle the mouse click toggling off the 'Auto On' label (which isn't included in your sample script, but I'm assuming you've already got that sorted).

Button trick?

Posted: Fri Aug 15, 2008 7:23 pm
by asayd
Hi bjb007,

It sounds like what you want to do, if I'm following you, is to:

- Exectue some handler repeatedly while your button is in a certain state; and

- Get out of that state and disable execution when the user clicks the button again.

Rather than imbed the send command in a repeat loop it's usually better to use the send in time construct, then have the called handler call itself unless your state has ended. It would go something like this:

Code: Select all

on mouseUp
  if the label of me is "Auto Off" then
    set the label of me to "Auto On"
    send "mouseUp" to button btnNextNumber
  else
    set the label of me to "Auto Off"
  end if
end mouseUp
Then in the called button:

Code: Select all

global gMsgID  -- could be 'local' if you never call it from other scripts
on mouseUp
  -- do stuff here
  if the label of btn "theOtherBtn" is "Auto On" then
    send "mouseUp" to me in 1 second
    put the result into gMsgID"
  else
    cancel gMsgID -- cancels any pending messages
  end if
end mouseUp
For a discussion of the send in time construct, see my web site http://revolution.byu.edu .
Click on Revolution Tutorials by Topic, then Scroll down to "Working with Dates, Time and Timing" and click on the link for "Executing Time-delayed or Repeating Events".

HTH

Devin Asay

Button

Posted: Sat Aug 16, 2008 3:49 am
by bjb007
Thanks SparkOut and asayd.

asayd...
What a great resource your site is.

Must remember to look there in future
when I need some help.