ID:159713
 
Hello, uhm, I was just wondering if there was a way to make it so you could only enter a tile from one direction or side. What I mean is, say you had a tile

[]

And you only wanted people to enter it from the right side.
x
x [] <--
x
I'm fairly new to coding, but this would help me alot with what I'm trying to do. I know it probably has to do something with the built in Cardinal directions, NORTH, EAST, WEST, and SOUTH.

<></<also>
turf/SingleEntry
Enter(var/mob/M)
if(get_dir(src,M)==NORTH) return ..() //only allows entrance from the north, meaning they're moving south.
//also makes sure no other players/objects are in the way already
else return //don't let them in from other sides
In response to Falacy
Thank you so much Falacy!

Can I use this to make it so one can only enter from East, South, and West? I'm using these to make a 3D feel to the North edge of a platform, so you need to be able to walk along the edge. Thanks again for the help! It's much appreciated!
In response to Yurokei
turf/SingleEntry
Enter(var/mob/M)
if(get_dir(src,M)==NORTH) return ..()
else return
Exit(var/mob/M)
if(M.dir==NORTH) return ..()
else return

That should allow you to limit which directions they can Exit the turf in. And yes, to change which direction/s it allows you to enter/exit from; just change where it says NORTH to whatever direction you want.
If you want multiple directions available on a single turf do something like this:
if(M.dir==NORTH || M.dir==SOUTH)    return ..()
//would allow you to move up and down past the turf, but not left or right through it
In response to Falacy
Again, thank you. You're a genius. I see why Artemis holds you to such high praises. :) *If that's even a phrase? lol*
In response to Falacy
And another way to do the samething as in the last snippet with bit operators:
if(M.dir&3) return..()
return 0 // Too lazy to put else in where it really isn't needed (because of the return in the if())

3 is NORTH|SOUTH (1|2) >_>
This is a more generalized method:

turf
var
no_enter
no_exit

Enter(atom/movable/o)
if(o.dir & no_enter)
//If they're trying to enter from a direction
//that overlaps with the no_enter directions,
//disallow them from entering.
return 0

return ..() //Otherwise, return the value of the
//parent proc.

Exit(atom/movable/o)
if(o.dir & no_exit)
//Same as above, but with the no_exit variable.
return 0

return ..()

Now, for the no_enter and no_exit variables, you would set them equal to a direction flag, with the | (pipe) symbol between them. For example, if you wanted them to not be allowed to enter from the north and east, but are also not allowed to exit from the north and south, you would do this:
no_enter = NORTH | EAST
no_exit = NORTH | SOUTH
In response to Popisfizzy
Popisfizzy wrote:
> no_enter = NORTH | EAST
> no_exit = NORTH | SOUTH
>


And then when he wants them to only be able to enter/exit from 1 direction he has to set 7 flags?
In response to Falacy
Well, if you're completley ignorant of how bitflags work, yes. If you have some idea, though, no:
no_enter = SOUTH | EAST | WEST
no_exit = SOUTH | EAST | WEST
In response to Popisfizzy
Popisfizzy wrote:
Well, if you're completley ignorant of how bitflags work, yes. If you have some idea, though, no:

Yea pretty much, feel free to explain o.O
In response to Falacy
NORTHWEST = NORTH | WEST
NORTHEAST = NORTH | EAST
SOUTHWEST = SOUTH | WEST
SOUTHEAST = SOUTH | EAST
In response to Popisfizzy
Popisfizzy wrote:
> NORTHWEST = NORTH | WEST
> NORTHEAST = NORTH | EAST
> SOUTHWEST = SOUTH | WEST
> SOUTHEAST = SOUTH | EAST
>


How is it stored though? Since that other guy said 3 represents NORTH|SOUTH since they're 1|2.
In response to Falacy
... they're stored exactly like that. NORTHWEST = NORTH|WEST = 1|8 = 9, and if you output the value of NORTHWEST you'll get 9.
In response to Popisfizzy
Popisfizzy wrote:
... they're stored exactly like that. NORTHWEST = NORTH|WEST = 1|8 = 9, and if you output the value of NORTHWEST you'll get 9.

So if it stores them as a numerical total of all variables combined. How would adding more than 2 variables work? You'd end up with something like NORTH|EAST|WEST which would yield 13 o.O
In response to Falacy
...

Okay, it's very obvious I'm not getting anywhere. Read this, then read the thread again.
In response to Popisfizzy
Popisfizzy wrote:
Okay, it's very obvious I'm not getting anywhere. Read this, then read the thread again.

AH HOH! so its not actually a numerical value, but binary. Each bit representing a different switch in said binary. Makes sense now =P And in any value that would require 2 switches to be on, it returns as true if either is on.
In response to Falacy
It's still a numerical value (As numbers can be represented in multiple systems different. 1110, B16, and 10112, for example). It's just easier to conceptualize when rendered in binary.