ID:2126283
 
(See the best response by Ter13.)
Code:
area
test
Entered()
world << "[x] and [y]"


Problem description: If a mob enters an area I am trying to print its current tile x and y but the above code always gives one value (13 and 15)...

If you want the coordinates of the mob, you should use the coordinates of the mob.
Best response
Entered() takes two arguments:

atom/movable/o (the movable atom that entered the atom)

atom/oldloc (the atom that the movable was standing in prior to moving into this one)

area
test
Entered(atom/movable/o,atom/oldloc)
world << "([o.x], [o.y], [o.z])"


when you just typed x and y, you weren't specifying the object that x and y belongs to. When you don't specify the object that a variable belongs to when accessing it in a proc, it will default to src. Src is always the instance of the type (or derived type) of object you defined the proc under, so in this case src is an instance of /area/test.

x and y of an area will always be equal to the first turf that is part of that area. So in this case, the area's first turf is located at 13,15 in your world. The only way you can tell which turf the area entry was triggered by is to check against the movable atom that triggered the entry function to find their location.

There is no way to directly get which turf was the one that triggered the entry into the area reliably without looping over the atom's locs variable:

area
test
Entered(atom/movable/o,atom/oldloc)
world << "([o.x], [o.y], [o.z])"
var/turf/t
for(t in o.locs)
if(t.loc==src)
break
world << "[t] is the turf that was entered."


In tile-movement mode, where the movable's bounding size is only the size of one single tile, you can just assume that o.loc is the turf that triggered the entry.

Another quick, but inefficient way is to AND the two lists together:

area.contents&o.locs


This will almost always be slower than looping through o.locs because o.locs will almost always be smaller than area.contents.