ID:179269
 
Foomer helped me out with this before, but somehow it doesn't seem to be working,

here is the code I am using:

turf/barw
icon = 'barw.dmi'
density = 0
dir = WEST
Enter(atom/movable/O)
if(!O.density) return ..() // if O's not dense, ignore all this
if(O.dir == NORTH) return ..()
if(O.dir == WEST) return ..()
if(O.dir == SOUTH) return ..() // if facing north, let it through
else return 0 // else return 0, or don't let it enter.
Exit(atom/O)
if(O.density) return ..()
if (O.dir == NORTH) return ..()
if (O.dir == EAST) return ..()
if (O.dir == SOUTH) return ..()
else return 0

Now I am defining this on a turf and the Enter() conditional is working but I cant seem to get the Exit() conditional to work. I get no compile errors, however, the mob can still exit any directionfrom the square, What am I missing?
Illyena wrote:
Now I am defining this on a turf and the Enter() conditional is working but I cant seem to get the Exit() conditional to work. I get no compile errors, however, the mob can still exit any directionfrom the square, What am I missing?

Your code seems to be contingent on O.dir being set before it moves, which may not be the case. Part of the problem is that Enter() and Exit() should be--but aren't--given an additional argument indicating where the atom is coming from and where it's going, respectively. Without this information, you have to rely on workarounds.

I have one such workaround for you:
atom/movable
Move(newloc,newdir)
dir=newdir
..()

This should help your code work correctly.

In addition, I recommend you change your direction checks as follows:
Enter(atom/movable/O)
if(O.density && (O.dir&EAST)) return 0 // this also covers diagonals
return ..()
Exit(atom/O)
if(O.density && (O.dir&WEST)) return 0
return ..()

Or, if you use the dir var to control which way the tile blocks, you can actually try this code for all similar tiles:
Enter(atom/movable/O)
if(O.density && (O.dir&dir)) return 0
return ..()
Exit(atom/O)
if(O.density && (O.dir&turn(dir,180))) return 0
return ..()

Lummox JR
In response to Lummox JR
Lummox JR thankyou for showing me how to make the code more compact, although most of what you said was WAY confusing and I have no Idea how it might be applied or the syntax to use if doing so.

However in reference to my original message the section

Exit(atom/O)
if(O.density) return ..()
should have been

Exit(atom/O)
if(!O.density) return ..()

A single exclamation and I loose an entire day beating myself up in desparation.

Thankyou all for the help.

Illya