LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
bjb007
- Posts: 313
- Joined: Fri Dec 28, 2007 4:56 am
Post
by bjb007 » Mon Sep 22, 2008 9:59 am
Mark
The code is...
Code: Select all
on mouseDown theButton
put the label of me into myCounter
put myCounter into field fldCount
if theButton is 1 then
add 1 to myCounter
else if theButton is 3 then
if myCounter > 0 then
subtract 1 from myCounter
end if
end if
put myCounter into field fldCount
set the label of me to myCounter
end mouseDown
and just doing a rough test using the 1-second
tick of my study clock I'd say that the delay
between right mouse click has to be more
than one second - more like 2 seconds - for
it to subtract without getting confused.
Left click? Slow too because it really be
instantaneous I feel.
The stand-alone is no better and not putting
label into fldCount doesn't help either.
Life is just a bowl of cherries.
-
SparkOut
- Posts: 2947
- Joined: Sun Sep 23, 2007 4:58 pm
Post
by SparkOut » Mon Sep 22, 2008 1:22 pm
On a bit of a tangent, I was wondering whether the efficiency of the handler might be improved without the "if" clause and did the process mathematically like:
Code: Select all
on mouseDown theButton
put the label of me into myCounter
add (2 - theButton) to myCounter
set the label of me to myCounter
end mouseDown
(and this is really a "wonder" - not saying that it should be, I'm fishing for some info, not stating a fact). Of course it's actually got nothing to do with the efficiency of the handler, rather the messages falling between mouseDown and mouseDoubleDown/mouseDoubleUp interpretation that's the problem.
-
SparkOut
- Posts: 2947
- Joined: Sun Sep 23, 2007 4:58 pm
Post
by SparkOut » Mon Sep 22, 2008 1:37 pm
I can confirm also that using mouseDown and mouseDoubleDown is not working as consistently as mouseUp and mouseDoubleUp.
My code snippet here seems quite workable
Code: Select all
on mouseUp theButton
put the label of me into myCounter
add (2 - theButton) to myCounter
set the label of me to max (0, myCounter)
end mouseUp
on mouseDoubleUp theButton
put the label of me into myCounter
add (2 - theButton) to myCounter
set the label of me to max (0, myCounter)
end mouseDoubleUp
-
bjb007
- Posts: 313
- Joined: Fri Dec 28, 2007 4:56 am
Post
by bjb007 » Mon Sep 22, 2008 2:16 pm
My last post seems to have gone down
a black hole...
The required time between right mouse clicks
to avoid problems is over one second and
probably nearer two - rough test agains the
ticks of my study clock.
Left clicks are slow too but at least they always
add.
Code: Select all
on mouseDown theButton
put the label of me into myCounter
---put myCounter into field fldCount
if theButton is 1 then
add 1 to myCounter
else if theButton is 3 then
if myCounter > 0 then
subtract 1 from myCounter
end if
end if
---put myCounter into field fldCount
set the label of me to myCounter
end mouseDown
Life is just a bowl of cherries.
-
SparkOut
- Posts: 2947
- Joined: Sun Sep 23, 2007 4:58 pm
Post
by SparkOut » Mon Sep 22, 2008 3:59 pm
Well did you try what has been suggested and change mouseDown to mouseUp? Also did you try adding a mouseDoubleUp handler? What happens if you replace the code in the button with the code I put above - including the mouseDoubleUp handler?
The reason you are getting problem results seems to be that there has to be a minimum delay between clicks in order to get a mouseDown/Up message - otherwise the mouseDoubleDown/Up message will be generated. On Mac/Linux the doubleClickInterval can be set (in milliseconds) but on Windows it is a read only property and will be read from the host system. If you're using Windows, in the control panel settings for the mouse do you have a slow double-click speed set?
If you are clicking quickly on the count button then to catch the messages you need to have the mouseDoubleUp handler in place as well as the single click handler. Also for whatever reason, the mouseDown response seems to be less consistent than mouseUp/mouseDoubleUp - so try that and see if it helps.
-
bn
- VIP Livecode Opensource Backer

- Posts: 4172
- Joined: Sun Jan 07, 2007 9:12 pm
Post
by bn » Mon Sep 22, 2008 4:01 pm
bjb,
please try the combination of mouseUp and mouseDoubleUp as has been suggested, including code, by SparkOut and me in this thread and see if it makes a difference.
regards
bernd
-
SparkOut
- Posts: 2947
- Joined: Sun Sep 23, 2007 4:58 pm
Post
by SparkOut » Mon Sep 22, 2008 4:40 pm
From the documentation:
Rev documentation wrote:If the mouse has moved outside the control that was originally clicked before the user releases the mouse button, the mouseRelease message is sent instead of mouseUp. If the click is the second click of a double click, the mouseDoubleUp message is sent instead of mouseUp.
Tip: If the user clicks several times in rapid succession (for example, if the user clicks an "Increase" button that increases a number by 1), some of the clicks may send a mouseDoubleUp message instead of mouseUp. If your script only handles the mouseUp message, these accidental double clicks will be lost. One way to prevent this is to install a handler in an object that's further in the message path, to re-send double clicks: [...and goes on to give sample code...]
or in the case of a simple handler like this situation, repeat for mouseDoubleUp events.
-
bjb007
- Posts: 313
- Joined: Fri Dec 28, 2007 4:56 am
Post
by bjb007 » Tue Sep 23, 2008 3:21 am
I've tried many possible combinations -
except mouseSideways and mouseInTheBin
but the result seems to be that two fast
right-clicks results in the action of one left-click
i.e. 1 added when one would expect either
1 subtracted (if either click was "lost") or
no action if they're interpreted as a double-click.
Then there's the slow response time which
definitely should be better than it is.
In "olden times" when typists could easily
outpace the speed of the computer the keyboard
had a "buffer" which held key-presses until
the programme was ready for the next character.
Do they still? Is there a mouse-click buffer?
Life is just a bowl of cherries.
-
SparkOut
- Posts: 2947
- Joined: Sun Sep 23, 2007 4:58 pm
Post
by SparkOut » Tue Sep 23, 2008 8:26 am
There is a mouse click handler on your computer which interprets single clicks as single clicks and clicks which are very close together as double-clicks. This is what you are no doubt used to in operating your computer applications. Rev is behaving in exactly the way you'd expect as far as deciding whether a click is to be registered as a click or whether it's part of a double-click combination. (Putting two button 3 clicks together to make button 1 responses is another matter BUT it has absolutely no bearing on the issue you can solve by simply adding the mouseDoubleUp handler.) The reason there is a "delay" is because if you are clicking rapidly, then clicks within the interval set on your computer control panel are interpreted as mouseDoubleUp events - and if you have no handler for these events, then the mouse clicks are lost.
I have put your stack with this revised script on my RevOnline space. Please try that. It works perfectly here.
-
Mark
- Livecode Opensource Backer

- Posts: 5150
- Joined: Thu Feb 23, 2006 9:24 pm
-
Contact:
Post
by Mark » Tue Sep 23, 2008 10:01 am
Hi Bjb, SparkOut and Bernd,
I have tested SparkOut's stack. If I try a double-click, assumingly it executes a mouseDoubleUp and a mouseUp (I'm having an issue with the script editor while writing this, so I can't look at the script in the default button on that stack).
I think we are mixing up a few problems, here. One of them being that after a mouseDoubleUp the mouseUp handler still runs. This is "normal" behaviour, designed by Bill Atkinson himself. Read more here:
http://quality.runrev.com/qacenter/show_bug.cgi?id=3567
Best,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
-
bn
- VIP Livecode Opensource Backer

- Posts: 4172
- Joined: Sun Jan 07, 2007 9:12 pm
Post
by bn » Tue Sep 23, 2008 10:07 am
Hi SparkOut,
thats brilliant, I especially like
Code: Select all
add (2 - theButton) to myCounter
-- and
set the label of me to max (0, myCounter)
no IF THEN and stuff, fast and smart
thanks
Bernd
-
SparkOut
- Posts: 2947
- Joined: Sun Sep 23, 2007 4:58 pm
Post
by SparkOut » Tue Sep 23, 2008 10:37 am
Mark wrote:Hi Bjb, SparkOut and Bernd,
I have tested SparkOut's stack. If I try a double-click, assumingly it executes a mouseDoubleUp and a mouseUp (I'm having an issue with the script editor while writing this, so I can't look at the script in the default button on that stack).
Yes, there's a mouseUp which is handled for the first click, and when followed quickly by another it invokes the mouseDoubleUp instead. So for two clicks (in quick succession) you'll get two handlers invoked, but only one of each mouseUp and mouseDoubleUp. That means that to increment the button by one for each and every click, then both the mouseUp and mouseDoubleUp handlers should increment the count by 1. (Not as may be thought that the mouseDoubleUp would block the mouseUp and have to increment the counter twice). This is covered in the Rev dictionary (at least in version 2.8.1-gm3 onwards, maybe prior to that but I don't have a copy to check) as quoted in my post above.
Mark wrote:I think we are mixing up a few problems, here. One of them being that after a mouseDoubleUp the mouseUp handler still runs. This is "normal" behaviour, designed by Bill Atkinson himself. Read more here:
http://quality.runrev.com/qacenter/show_bug.cgi?id=3567
Best,
Mark
Oddly, on my Windows XP machine, for quick clicks, the messages are:
mouseDown
mouseUp
mouseDoubleDown
mouseDoubleDown
mouseDoubleUp
Quite why there are two messages for mouseDoubleDown I don't know, and that's probably got something to do with why the "Up" way works a lot better.
And Bernd, thanks. I was looking for some thoughts on that - I believe that mathematical processes like that must be more efficient than conditional tests, but I don't know how to make a definitive comparison.
-
SparkOut
- Posts: 2947
- Joined: Sun Sep 23, 2007 4:58 pm
Post
by SparkOut » Tue Sep 23, 2008 11:04 am
Now this is really weird:
SparkOut wrote:Oddly, on my Windows XP machine, for quick clicks, the messages are:
mouseDown
mouseUp
mouseDoubleDown
mouseDoubleDown
mouseDoubleUp
when I'm clicking the button which has mouseUp and mouseDoubleUp handlers specified. I changed the handlers to mouseDown and mouseDoubleDown to see how that affected things and try to follow the messages. The results where that for 10 "rapid" (left)clicks the counter was incremented by a total of 15, and for 10 "rapid" right-clicks the counter was decremented by a total of 5 (it was possible to see the label being set down by two and then having an extra count added back).
In this case, following the messages I observed:
mouseDown
mouseUp
mouseDoubleDown
mouseDoubleDown
mouseDown
mouseUp
Which has baffled me. The messages that are triggered should be the same, regardless of what handlers have been set to catch them, isn't that correct? How can changing the handlers in a button actually change the messages that are generated by the clicking actions?
-
bn
- VIP Livecode Opensource Backer

- Posts: 4172
- Joined: Sun Jan 07, 2007 9:12 pm
Post
by bn » Tue Sep 23, 2008 11:33 am
sparkout,
I benchmarked the math version and the if-then version with this script
Code: Select all
on mouseUp pMouseBtnNo
put 10000 into tRounds -- adjust the rounds here
put the millisec into tStartMath
repeat for tRounds
put 3 into theButton
put 5 into myCounter
add (2 - theButton) to myCounter
put max (0, myCounter) into tLabelVariable
put max (0, myCounter) into tFieldVariable
end repeat
put the millisec - tStartMath into tTimeForMath
put the millisec into tStartIF
repeat for tRounds
put 3 into theButton
put 5 into myCounter
if theButton = 1 then
add 1 to myCounter
else if theButton is 3 then
if theButton > 1 then
subtract 1 from myCounter
end if
end if
end repeat
put the millisec -tStartIF into tTimeForIF
put "Time for math " & tTimeForMath & return & "Time for IF " & tTimeForIF
end mouseUp
Assuming this reflects the core differences between the two approaches the IF-Then is faster to my surprise, still I like the beauty of the math approach. And since on a macbook pro 10000 times for math is around 14 millisecs and for IF-Then 9 millisecs, it is not that much of a difference. Unless you do it for many many times like in working on imagedata, where you easily do stuff like this in the million.
cheers
Bernd
-
SparkOut
- Posts: 2947
- Joined: Sun Sep 23, 2007 4:58 pm
Post
by SparkOut » Tue Sep 23, 2008 11:43 am
Thanks Bernd
Only I noticed that you didn't "put myCounter into" the variable holders like with the mathematical approach.
Adding
Code: Select all
put myCounter into tLabelVariable
put myCounter into tFieldVariable
just above the end repeat loop for the if..then approach, on my Win XP laptop the results are:
Time for math 19
Time for IF 22