ID:96886
 
Keywords: click, dblclick
I want my player to be able to walk up to a door by clicking on it, and then open it with a double click without automatically stepping into the doorway. The player would have to manually register a second click to move into the opened door. The following code addresses the issue. The only catch is that the player cannot double-click to close the door again.

Client code:
client
var
double_click = 0

Click(atom/L)
// Don't pass a second Click() to the object when DblClick()'d
if (double_click)
double_click = 0
else
..()

DblClick(atom/L)
double_click = 1
..()


Door code:
obj/door

New()
..()
// created in closed state
close()

verb
open()
set src in oview(1)
density = 0
opacity = 0
verbs -= /obj/door/verb/open
verbs += /obj/door/verb/close

close()
set src in oview(1)

if(loc)
var/obj/door_stop = locate() in (loc.contents - src)
if(door_stop)
usr << "The door is blocked by \a [door_stop]."
return

density = 1
opacity = 1
verbs -= /obj/door/verb/close
verbs += /obj/door/verb/open

proc
is_open()
return (0 == density)

DblClick()
if(usr in oview(1,src))
if(is_open())
close()
else
open()

Click()
if (is_open())
walk_to(usr,src.loc)
else
walk_to(usr,src.loc,1)



edit: changed code that tests for door blockage
You could always have a delay when the first click is made. Make a variable that is set to 0 and the double click will change it back to 1? Only real solution I can think of.