Jump to content
IGNORED

Is there a better way to double click?


Random Terrain

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

doubleclick.bas

doubleclick.bas.asm.txt

doubleclick.bas.bin

Link to comment
Share on other sites

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:

Link to comment
Share on other sites

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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...