Found how to disable double-click select while allowing drag select

Hello all!

Story Format: SugarCube 2.34.1

This could be useful if you have something like a story-heavy clicker game (that’s what I’m using it for).

I wrap the spot in <span class="clicker" id="clicker"></span>, and put in the Stylesheet:

.clicker {
  user-select:none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -khtml-user-select: none;
}

Then in the StoryInit passage I use Chapel’s event macro:

<<on 'mousedown' '#clicker'>>
<<if $up is 2>>
<<set $up to 0>>
<<addclass "#clicker" "clicker">>
<</if>>
<<on 'mousemove' '#clicker'>>
<<removeclass "#clicker" "clicker">>
<<set $up to 1>>
<</on>>
<</on>>

<<on 'mouseup' '#clicker'>>
<<if $up is 1>>
<<set $up to 2>>
<</if>>
<</on>>

Of course this probably needs improvement (for example it seems you need to drag twice at first for some reason), but it seems to work without breaking anything… maybe? :slight_smile:

Oh, and I noticed again while working this out that the event macro doesn’t seem to work with the <<else>> tag, it does weird stuff.