ID:1385157
 
(See the best response by Doohl.)
Code:
turf/door
icon = 'door.dmi'
name = "Door"
icon_state = "closed"
density = 1

proc/toggle()
if(density)
density = 0
icon_state = "open"
return
if(!density)
density = 1
icon_state = "closed"
return

Click()

if(!(src in view(1,usr)))
return 0

toggle()
return


Problem description:
Opening the door works fine, but when i close it, nothing happens, it just stays in its open state and is passable :(

Edit: I made a verb on the door just to test to see, i cant even access that verb once its opened, what is this black magic?
Best response
For one, you don't really want to use if() statements like that, even if you are returning before the next conditional can be called.

I think it would be cleaner if you tried something like this:

proc/toggle()
density = !density

if(density) icon_state = "closed"
else icon_state = "open"


Also there is no need to return after calling toggle() in Click().
Thanks! Also how do i vote?
It still gets stuck, this is all the code i have:

turf/door
icon = 'door.dmi'
name = "Door"
icon_state = "closed"
density = 1

proc/toggle()
/*if(density)
density = 0
icon_state = "open"
return
if(!density)
density = 1
icon_state = "closed"
return*/

density = !density

if(density) icon_state = "closed"
else icon_state = "open"
'


Click()

//if(!(src in view(1,usr)))
// return 0

if(get_dist(src,usr) <= 2)
toggle()
It seems like something else is going on outside of the code you have provided. Could you describe in further detail what you mean by getting stuck?

The best I can think of is that somehow density is messing with view() and get_dist(), but I've never run across issues with that.
Uhh all i have is an overwritten move proc to limit speed.
Ill post the code later, i have a job. :P
The only thing I can think of is a black void is present. If your open state is simply an invisible square, the black space you click won't be registered. There are a handful of solutions to this, but the best I can think of is to ctrl-click when mapping your door. This will give it an underlay of whatever your grass/floor is.

You can also manually apply an underlay.
turf/Door
underlay=list(/turf/grass)
Making it an obj fixed the problem, i cant place two turfs in one place, apparently..