ID:1846698
 
(See the best response by F0lak.)
Code:
Click()
if(src in oview(1))
if(istype(usr,/mob/player))
src.icon_state = "jaildooropen"
src.density = 0
view() << 'door.wav'
loop
sleep(20)
if(src.loc == usr.loc)
goto loop
else src.icon_state = "jaildoor"; src.density = 1


Problem description:
So this is what I've got. It's supposed to wait 2 seconds then close unless the usr is in the same location. But the door closes under the usr anyways. Any ideas?
Is this door an object or a turf? If it is a turf the usr will never be in the loc of the turf, since a mob would reside on the turf, not its location.
Well I have instances of both. I have it set up so players create objs, that way when the world map is saved it only needs to save objs to keep load time down.

Anyways, the code I have doesn't work for either instance.
Best response
You want to use a while() or for() loop instead of goto. Just, don't ever use goto.

The 'usr' of Click() is always going to be a player, unless you're changing their mob path at some point to be something other than a player. Just remember, NPC's can't click, unless you're doing something really weird.

You can do an easy while loop as follows.

while(locate(atom/movable) in orange(0,src))
world << "door is still propped"
sleep(10) // wait another second
world << "closing the door"


This way you can have the door close after someone has left the tile, and have it stay open while they're on it.

It's not the best way to go about it, I'm sure but I am tired.
You're my boy, F0lak!
In response to F0lak
F0lak wrote:
You want to use a while() or for() loop instead of goto. Just, don't ever use goto.

Goto has its uses; this just isn't one of them. It's a tool for experienced programmers who know when nothing else will work quite as well.
I swapped the if for a while and it works fine, hah. Thanks!