ID:150158
 
I am trying to make stairs and instead of making walls on either side of the stairs, I want to block access to the stairs from east and west. The code below seems to block access from ANY directions. Maybe you can see something wrong with the code that I can't.

area
var/list/unallowed_enter
Enter(atom/M)
if(ismob(M))
var/dir = get_dir(M,src)
if(unallowed_enter == null) return 1
if(unallowed_enter.Find(dir)) return 1
else
. = ..()
upstairs
New()
unallowed_enter = list(EAST,WEST)
..()
downstairs
New()
unallowed_enter = list(EAST,WEST)
..()
Have you tried Entered()?
In response to Nadrew
That allows access from ANY direction. :(
You should implement your stairway as a turf rather than an area. The problem is that get_dir() doesn't really make sense for areas. What if I have a U-shaped area and I'm in the middle of it? What should get_dir() return? The area exists in at least 3 directions from me. What's happening is that get_dir() just returns SOUTH as a kind of default value I suppose, no matter where you try to enter from. So you get inside the if(ismob(M)) block of code and your dir is not found in unallowed_enter, so nothing happens and Enter() doesn't return anything at all. Thus entry is blocked.

With a turf, get_dir() makes sense and will do what you expect. Change the area to turf and you should be pretty good to go. The only other thing I see is that you should return 1 if the dir is not found in unallowed_enter:
             if(!unallowed_enter.Find(dir)) return 1