Jump to content



1

Is there a better way to double click?


11 replies to this topic

#1 Random Terrain ONLINE  

Random Terrain

    Visual batari Basic User

  • 20,910 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Sat Mar 15, 2008 5:24 PM

I'm thinking of adding the ability to double click or maybe even triple click the fire button in a program I'm working on. I can think of an obvious, bloated way to do it, but is there a really good way to double click or triple click that requires fewer variables?

Thanks.

#2 MausGames OFFLINE  

MausGames

    Dragonstomper

  • 851 posts
  • Location:MO, USA

Posted Sat Mar 15, 2008 5:31 PM

It only requires one variable. Ex:

if joy0fire && a = 0 then a = 1
if !joy0fire && a = 1 then a = 2 - pressed and released once.
if joy0fire && a = 2 then a = 3
if !joy0fire && a = 3 then a = 4 - pressed and released twice.
if joy0fire && a = 4 then a = 5
if !joy0fire && a = 5 then a = 6 - pressed and released for a third time.

Ok, two variables if you want "a" to reset after the button isn't pressed for a certain time -
if !joy0fire then b = b + 1 else b = 0
if b = 10 then a = 0 : b = 0

I'm sure this is probably the obvioius, bloated method you were referring to, but I know of no other way to accomplish this.

#3 Random Terrain ONLINE  

Random Terrain

    Visual batari Basic User

  • 20,910 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Sat Mar 15, 2008 5:38 PM

View PostMausGames, on Sat Mar 15, 2008 7:31 PM, said:

I'm sure this is probably the obvioius, bloated method you were referring to, but I know of no other way to accomplish this.
Thanks. I was thinking that I might have to use at least 3 variables, so that's better than what was in my head. If there's a more bloated, variable wasting way to do something, I'll usually think of that first.

#4 SeaGtGruff OFFLINE  

SeaGtGruff

    River Patroller

  • 4,543 posts
  • Location:Georgia, USA

Posted Sun Mar 16, 2008 1:38 AM

View PostMausGames, on Sat Mar 15, 2008 7:31 PM, said:

It only requires one variable. Ex:

if joy0fire && a = 0 then a = 1
if !joy0fire && a = 1 then a = 2 - pressed and released once.
if joy0fire && a = 2 then a = 3
if !joy0fire && a = 3 then a = 4 - pressed and released twice.
if joy0fire && a = 4 then a = 5
if !joy0fire && a = 5 then a = 6 - pressed and released for a third time.

Ok, two variables if you want "a" to reset after the button isn't pressed for a certain time -
if !joy0fire then b = b + 1 else b = 0
if b = 10 then a = 0 : b = 0

I'm sure this is probably the obvioius, bloated method you were referring to, but I know of no other way to accomplish this.
I think you'll probably end up wanting to go with an approach that allows for debounce. The first example doesn't reset the counter variable, so if you pressed the button once and let go, waited for a minute, then pressed the button again, it would count as a double-click, even though the clicks were a minute apart. I think what you probably want is for the second click to count as a double-click only if the button's pressed within a certain brief period of time after the first click. You should be able to do that with just one variable, if you want the debounce period to have a fixed length. But if you want the user to be able to adjust the debounce period (as with most mouse drivers, so you can do a "lazy double-click"), then it would take at least two variables. I'll see able posting an example later tonight.

Michael

#5 SeaGtGruff OFFLINE  

SeaGtGruff

    River Patroller

  • 4,543 posts
  • Location:Georgia, USA

Posted Sun Mar 16, 2008 1:40 AM

View PostRandom Terrain, on Sat Mar 15, 2008 7:38 PM, said:

If there's a more bloated, variable wasting way to do something, I'll usually think of that first.
That just means you're like the rest of us programmers! ;)

Michael

#6 Random Terrain ONLINE  

Random Terrain

    Visual batari Basic User

  • 20,910 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Sun Mar 16, 2008 4:07 AM

View PostSeaGtGruff, on Sun Mar 16, 2008 3:38 AM, said:

I think you'll probably end up wanting to go with an approach that allows for debounce. The first example doesn't reset the counter variable, so if you pressed the button once and let go, waited for a minute, then pressed the button again, it would count as a double-click, even though the clicks were a minute apart. I think what you probably want is for the second click to count as a double-click only if the button's pressed within a certain brief period of time after the first click. You should be able to do that with just one variable, if you want the debounce period to have a fixed length. But if you want the user to be able to adjust the debounce period (as with most mouse drivers, so you can do a "lazy double-click"), then it would take at least two variables. I'll see able posting an example later tonight.
I think a fixed length of time between fire button clicks would be good enough. As long as the length of time is reasonable, people should be happy with it.

Giving users the ability to double click and triple click with the fire button should allow them do just about everything from the joystick instead of needing to mess with switches on the console.


Thanks.

#7 batari OFFLINE  

batari

    )66]U('=I;B$*

  • 6,236 posts
  • begin 644 contest

Posted Sun Mar 16, 2008 6:14 PM

Double-clicking has its uses, but there are some limitations as well. Namely, any game that allows single- and double-clicks will require a slight loss in reaction times. A single-click cannot register until a "time-out" period is up, and a double-click will not register until the second click, which for the average person, I believe is around 6-10 frames.

In a single-click game, for example, a missile can fire less than 1/60th of a second after a button press. In a double-click game, the time would be 1/10th at best, if using a double click, and maybe 1/2 second at worst, if that's the double-click timeout period.

That said, there are alternatives, as I did use a single-click for firing an arrow and a double-click for distance calculation to the Wumpus in my improvements of vdub_bobby's Hunt the Wumpus (download here.) It's not exactly the kind of double-clicking described here, as a single-click requires a joystick direction to fire and a double-click must be done while standing still, and there is no time-out period for double clicks (not really needed here.)

#8 Random Terrain ONLINE  

Random Terrain

    Visual batari Basic User

  • 20,910 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Sun Mar 16, 2008 6:26 PM

View Postbatari, on Sun Mar 16, 2008 8:14 PM, said:

Double-clicking has its uses, but there are some limitations as well. Namely, any game that allows single- and double-clicks will require a slight loss in reaction times. A single-click cannot register until a "time-out" period is up, and a double-click will not register until the second click, which for the average person, I believe is around 6-10 frames.

In a single-click game, for example, a missile can fire less than 1/60th of a second after a button press. In a double-click game, the time would be 1/10th at best, if using a double click, and maybe 1/2 second at worst, if that's the double-click timeout period.

That said, there are alternatives, as I did use a single-click for firing an arrow and a double-click for distance calculation to the Wumpus in my improvements of vdub_bobby's Hunt the Wumpus (download here.) It's not exactly the kind of double-clicking described here, as a single-click requires a joystick direction to fire and a double-click must be done while standing still, and there is no time-out period for double clicks (not really needed here.)
Thanks. I'm working on a tool, not a game, so a loss in reaction time isn't that big of a deal. I probably wouldn't use it in a game, although I could imagine using double click in a turn-based game.

#9 Fort Apocalypse OFFLINE  

Fort Apocalypse

    Stargunner

  • 1,593 posts

Posted Tue Mar 18, 2008 9:27 PM

Attached is a sample drawing program which uses double-click.

You click and drag to draw or double-click to erase a dot. I've also made the playfield stay red during the double-click check to make it obvious how long it is waiting on the double-click.

I didn't look at previous source examples so I may not be doing things in the optimal way, but maybe it will help you.

Attached Files



#10 Fort Apocalypse OFFLINE  

Fort Apocalypse

    Stargunner

  • 1,593 posts

Posted Tue Mar 18, 2008 9:28 PM

obligatory screenshot

Attached Thumbnails

  • doubleclick.bas.bin.png


#11 Random Terrain ONLINE  

Random Terrain

    Visual batari Basic User

  • 20,910 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Tue Mar 18, 2008 9:39 PM

View PostFort Apocalypse, on Tue Mar 18, 2008 11:27 PM, said:

Attached is a sample drawing program which uses double-click.

You click and drag to draw or double-click to erase a dot. I've also made the playfield stay red during the double-click check to make it obvious how long it is waiting on the double-click.

I didn't look at previous source examples so I may not be doing things in the optimal way, but maybe it will help you.
Thanks. Seeing a working example should help me out a lot. :thumbsup:

#12 Random Terrain ONLINE  

Random Terrain

    Visual batari Basic User

  • 20,910 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Wed Mar 19, 2008 4:20 PM

For anyone that might be interested, here is my version of the double-click based on what was posted:


 rem  *  Timer for double-click
 timer=timer+1 : if timer>10 then timer=10 : click=0

 rem  *  Fire button pressed and released once
 if joy0fire && click=0 then click = 1 : timer=0
 if !joy0fire && click=1 then click=0 : if timer<7 then click = 2 : timer=0

 rem  *  Fire button pressed and released twice for complete double-click
 if joy0fire && click=2 then click = 3 : timer=0
 if !joy0fire && click=3 then click=0 : if timer<7 then timer=0 : [the thing that needs doing goes here or is jumped to with a goto or gosub]

That seems to be working perfectly so far.

Thanks for the help.

Edited by Random Terrain, Sat Mar 22, 2008 6:18 PM.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users