Mouse polling answers for Scott

Geoff Canyon gcanyon at inspiredlogic.com
Thu Feb 28 21:34:01 EST 2002


At 1:52 PM -0800 2/28/02, Geoff Canyon wrote:
>At 12:05 PM -0700 2/27/02, Scott Raney wrote:
>>Can someone please verify this?  We've had two anecdotal reports that
>>SC does *not* work this way.  Running Geoff's example script will
>>clear up the issue once and for all I think.
>
>I tested SuperCard 3.5.1 with the following script:
>
>on mouseUp
>  repeat with i = 1000 down to 1
>    put i
>  end repeat
>  put the mouse
>end mouseUp
>
>If you click the button, the numbers run by, and the message box ends up with "up" -- so far so good.
>
>If you click the button, then do a half-click -- press and hold the mouse button -- the numbers run by, and the message box ends up with "down" -- this is also expected, and matches HC and Rev/MC.
>
>If you click twice, you get two possible behaviors, both of which differ from HC/MC/Rev. 
>
>  -- If the second click is outside the button, then the appropriate word is displayed at the end of the countdown -- down if the mouse button is depressed, up if it is not. You can click as many times as you like outside the button, only the actual state of the button at the end of the countdown is reflected.
>
>  -- If the second click (while the counter is running) is on the button, the button does a second mouseUp when it finishes the first. The word "down" or "up" correctly flashes by as SuperCard goes back to counting down from 1000. In fact, you seem to be able to queue as many mouseUps as you like -- click on the button five times quickly, and the counter will then proceed through five countdowns. At the end of each countdown, the current state of the mouse, either up or down, will flash by.

A correction: Revolution will also take a second (third, fourth, etc.) click while the button is counting down, and process them, the same as SuperCard will. HyperCard does not show this behavior.

For both HyperCard and MC/Revolution, the following will display the correct state of the mouse at the time, regardless of previous clicks:

on mouseUp
  repeat with i = 5000 down to 1
    put i
  end repeat
  get the mouse
  put the mouse
end mouseUp

Note the dual use of the mouse function; the first disposes of the (potentially) bogus value, while the second displays the correct value.

I just had a thought -- maybe I'm expressing something everyone here is aware of, but just in case, are we perhaps dealing with a bit of a semantic issue?

It would be easy to use "repeat while the mouse is down" and expect that this translates to "do this as long as the mouse button is pressed," but that's not what it really means. (Scott, correct me if I'm wrong) Like any other repeat loop, it simply tests the condition of the mouse function once each time through the loop. To make it clearer, the following two scripts are equivalent:

repeat while the mouse is down
--do something
end repeat

repeat
if the mouse is down then exit repeat
--do something
end repeat

The second simply makes it clearer what is happening.If the loop takes a while to execute, for example:

repeat while the mouse is down
  repeat with i = 5000 down to 1
    put i
  end repeat
end repeat

then it is possible for the mouse to go through any number of up and down states while the inner repeat is running, and the only thing that matters is whether the mouse happens to be down at the time the outer repeat loop checks it. The check isn't continuous. As an aside, Scott -- doesn't this mean that the following isn't true as long as the repeat loop is slow?

At 10:47 AM -0700 2/20/02, Scott Raney wrote:
>And the very worst thing to do with any of these is "repeat until
><function>", which will condemn you to the fires of eternal damnation
>in multiuser hell ;-)

I don't know where it might be useful, but a "repeat until <someMouseState>" that took five seconds each time through the loop wouldn't earn you a penalty from the OS, would it?

As a further example, put the above script in a button in HyperCard. Click the button. The script will count down once, because the mouse is up at the end. Click the button, then click _outside_ the button while the script is counting down. The script will count down exactly twice. As in the earlier script, the first time through, even though the mouse is up, the function returns down, so the outer loop goes again. The second time, the function has been cleared, so it returns up, the accurate value, and the loop exits. In HyperCard, the following script will count down only once, no matter how many times you click (outside the button) as long as the mouse button is up at the crucial point in time:

on mouseDown
  repeat while the mouse is down
    repeat with i = 5000 down to 1
      put i
    end repeat
    get the mouse -- clears the function
  end repeat
end mouseDown

Interestingly, Revolution doesn't seem to like any of these. I tried both of the above, and also:

 on mouseDown
  repeat
    get the mouse
    if the mouse is up then exit repeat
    repeat with i = 3000 down to 1
      put i
    end repeat
  end repeat
end mouseDown

and in all cases, Revolution just keeps looping through the countdown.

regards,

Geoff





More information about the use-livecode mailing list