So You Want A Tutorial: Doors and Teleporation
Well, that was a ridiculously long explanation to get a few lines of "correct" code.
-That if(istype(a)) doesn't seem like what you'd want. Allowing non-mobs (generally non-player-mobs) to enter doorways is usually undesirable.
turf/newturf Entered(mypath/foo) if(istype(foo)) ..()
-You never really explained how to set the tag variable.
-Implementing doorways as /turfs can be somewhat flunky, since all turfs in a single tile merge into a single entity. Now that the Cross type procs have been implemented, you can effectively use /objs for doorways.
-Building doorway code into Enter() is acceptable. Entered() could allow for potential blocking of doorways, which isn't necessary desirable. Enter() vs Entered() in your code would provide essentially identical results.
-Your code would also result in an instant movement as soon as they "touched" the doorway, which is generally a poor looking effect. If you're going to use Entered(), you may as well implement a graphically functional delay.
The caveat with this method is that BYOND's default movement interface never results in the Enter() proc being called for any type of /atom/movable. Consequently, this would require a change to the Move() proc in /atom/movable, which is a much more involved modification.
The Cross type procs work on movable atoms in essentially the same same way that Enter type procs would on a turf.
turf // This is the tag of the location we're moving to. var/moveto_tag Entered(atom/movable/a) if(istype(a)) // This stores the turf we're moving to. Note that tag // isn't only on turfs, but all /atom types. Therefore, // it's entirely possible that this is not a turf. // I do not typecheck here, though, because it is // up to the map designer to put a tag on the right // object, and they could have a reason for moving // the player to a non-turf. var/turf/t = locate(moveto_tag) if(t) a.loc = t
entrancel icon = 'person.dmi' icon_state = "castle-entrancel"
area warp Entered(mob/m) // the destination is the turf in this area // that the mob isn't standing on. var/turf/destination for(var/turf/t in src) if(t != m.loc) destination = t break m.loc = destination warp_01 warp_02 warp_03
Creating that extra destination var and then moving the mob after the loop is ugly. You could set m.loc=t in the loop. Also, you should throw an ismob(m) type check in there (and maybe return ..()), since you know noobs are gonna copy/paste this code and hope it works =P
var area/a = target_type ? (locate(target_type) in world) : srcm.loc = locate(/turf) in (a.contents - m.loc)
Readability is important.
Readability is important.
That was my point, I'm not sure why you're trying to post broken nonsense with no context.
His library is pointlessly overcomplicated, barely readable, and still has no type checking.
1. The context of my code is his library (specifically, in destination()), and it works.
2. Type-checking isn't very important if only movable atoms can enter areas.
3. If anything, the overcomplicating parts of his library make it even more readable.
"destination" is easier to understand to be a destination than "t", of course.
His library is pointlessly overcomplicated, barely readable,
turf/Enter(mob/m) m.loc = locate(4, 30, 1)
and still has no type checking.
warp // player-only warps: player_only warp(mob/player/p) if(istype(p)) ..()
It's certainly readable and isn't overcomplicated =)
The library makes no assumptions about what objects can or cannot use warps. That's not something the library would do
Entered() is a proc like any other, people could call it with whatever parameters they wanted.
It took him over 50 lines to accomplish what should be a perfectly readable example in less than 5.
The demos are what counts. If the library was only 5 lines it couldn't be as flexible and the demos would be more complex. The goal is to keep the demos (or whatever project uses the library) as simple as possible.
Also, lines of code isn't a good measure of complexity (consider Kaiochao's 2-line example above).
You're also counting whitespace and comments towards that total, it's really only 25 lines of code.
There is also a problem with both of these examples; if you want to have a doorway that is more than a single tile.