ID:1493102
 
(See the best response by Multiverse7.)
Problem description:
I have this inventory system where if you click once it'll display the item's description via interface. But if you dblclick(), it equips said gear / does as needed with the item. This is working and all but how would I go about detecting whether somebody clicked or dblclicked? right now when I dblclick it equips the item but also shows me the item's info, a behavior which is only intended if a player clicks once.

Help is much appreciated

-Thanks
obj
Click() // Clicked once
// Do click stuff

DblClick() // Clicked twice
// Do dblclick stuff
That's what I'm doing. It's just that when I click twice, it also does what it's supposed to do when I only click once
In response to FishMan123
humm can u show us your code?
Alright. My code is rather long though:
#define WEAPONS_1     FLOAT_LAYER -1

#define ARMOR_1 FLOAT_LAYER -5 //armor pants
#define ARMOR_2 FLOAT_LAYER -4

#define CLOTHES_2 FLOAT_LAYER -6 //shirts
#define CLOTHES_3 FLOAT_LAYER -3 // vest
#define CLOTHES_4 FLOAT_LAYER -2 // scarf


Equipment

parent_type = /Inventory

var/list/Clothes = list()
var Armor
var Weapons
var Armor_type
var/list/Arrangement = list()

verb/Get()
set hidden = 1
set src in oview(1)
src.Move(usr)
usr.Add_Items(src)

Click()

if(src in usr.contents)

var/Inventory_pos = winget(usr,"Inventory","pos")
winshow(usr,"Inventory",0)
winshow(usr,"Item_Info",1)
winset(usr,"Item_Info","pos=[Inventory_pos]")
spawn(2)

usr<<output(

{"
<b><font color = white>Item:</color><font color = green>
[src]</color>
<font color = white>Description:
[src.desc]


"}


,"Item_Info.Info")

sleep(world.tick_lag)


DblClick()
if(src in usr.contents)
switch(is_equipped)

if(TRUE)

for(var/obj/Maptext in usr.client.screen)
if(Maptext.tag == "[src]")
del(Maptext)

is_equipped = FALSE

switch(gear_type)

if("Clothing")
usr.clothing_equipped -= src
usr.overlays -= Clothes

if("Armor")
usr.armor_equipped -= src
usr.overlays -= Armor

if("Weapons")
usr.weapon_equipped = null
usr.overlays -= Weapons




if(FALSE)

new/Maptext("E","[src]",src.screen_loc,16,16,1)

is_equipped = TRUE

switch(gear_type)

if("Clothing")

switch(src.Arrangement)

if(2)
Clothes = image(icon = src.real_icon, layer = CLOTHES_4)
if(3)
Clothes = image(icon = src.real_icon, layer = CLOTHES_3)
if(4)
Clothes = image(icon = src.real_icon, layer = CLOTHES_2)

usr.clothing_equipped += src
usr.overlays += Clothes

if("Armor")

switch(src.Arrangement)

if(1)
Armor = image(icon = src.real_icon, layer = ARMOR_1)
if(2)
Armor = image(icon = src.real_icon, layer = ARMOR_2)

usr.armor_equipped += src
usr.overlays += Armor

if("Weapons")

usr.weapon_equipped = "[src]"
Weapons = image(icon = src.real_icon, layer = WEAPONS_1)
usr.overlays += Weapons
It's just that when I click twice, it also does what it's supposed to do when I only click once

So when u click twice it does what you want it to do but it also does what is supposed to do when u click once ?
Yeah
Thanks, Falcon! not working as I had hoped but that seemed to the the trick :P
Best response
Falcon lazorz wrote:
Upon DblClick() undo the Click() effects.

That's just silly.

Try using a timeout system to make sure only one of them can happen at once.

    var/tmp/double_clicked

Click(location, control, params)
..()
sleep(2)//The number of ticks to sleep before checking for double_clicked.
if(double_clicked)
double_clicked--//Here, we decrement double_clicked, until it reaches 0,
return//which allows us to cancel out 2 calls to this proc, as is necessary.
//The check for double_clicked failed,
//so do Click() stuff here.

DblClick(location, control, params)
..()
double_clicked = 2
//Do DblClick() stuff here.

You could probably only use Click() by itself with the right check, but then what would be the point of DblClick()?

Hopefully this works like I think it would.

Edit:
After actually testing this out, I realized that I would need to make sure that 2 Click() calls got cancelled, not just 1. That much should have been obvious to me...

Also, upon testing I discovered that all that was needed was a simple sleep() call to get the timing right, not any kind of fancy loop. In fact, trying to do this with loops was just really buggy, so this new system is surprisingly much more stable. The above code has been edited.
double_clicked should be a tmp variable.
I updated the code with a new version that should work far better.

Sorry if it had caused any issues.
You don't even really need to get that fancy.

obj
var/tmp/clicked = 0

Click()
if(clicked) return
clicked = 1
spawn(5)
if(src) clicked = 0
..()


DblClick() doesn't really need to be altered since the problem is just the second click of a double-click triggering Click(), adding a delay between the ability to execute Click() is more than enough to prevent that from happening.

Click once -> Success
Click twice (within half a tick) -> Failure, but DblClick() executes.

In response to Nadrew
That might work in specific cases, but not all. Your method really only solves half of the problem. Click() is normally called twice whenever DblClick() is called, so both calls to Click() need to be cancelled, otherwise you will still end up doing both what Click() does and what DblClick() does.

The way I understand it is that there is a conflict between the functionalities of each proc, and the OP only wants a single call in each case (either 1 Click() or 1 DblClick()).

I guess it just depends on how you are setting things up.
I would just like to share on how I would do this.

mob/proc/Equip_Item(var/obj/o)
obj
var tmp/clicked
proc/Display_Stats()
Click()

if(src.clicked == 2) return

src.clicked ++
if(src.clicked == 1)
src.Display_Stats()

spawn(5)
if(src.clicked == 1) src.clicked = 0
else if(src.clicked == 2)
src.clicked = 0
usr.Equip_Item(src)