ID:1668114
 
turf
Click()
new/turf/testturf(src)
var/turf/testturf/t = locate(src.x,src.y,src.z)
if(t==src)
world << "Surprise! This works!"
if(src.type==/turf)
world << "I bet you thought this would work."
//this code never runs, by the way.


Now, as for why this counter-intuitive bit of code actually works, you need to understand how turf references are stored in memory.

A turf reference is 5 bytes of data. 1 byte determining the type of the reference. Turfs are type #1. The remaining 4 bytes are the index of the turf. Turfs are indexed from 1,1, to maxx,maxy,maxz.

Turfs are expected to *always* be indexed by the order of placement in the world, and not necessarily by their order of creation, like movables.

Now, the trick to why this counter-intuitive code does in fact work, is that turfs are always referenced by their location, as I just mentioned. This means that if a new turf is created at location (2,2,1), the turf at that location is overwritten by the new turf.

Unfortunately, this means that for a very brief period of time, all currently running procs on the old turf are running under the new turf, with the new turf as src.

I'm curious to see how this affects things like while(src) loops running on specific turfs.

After some experimentation, I've discovered that while(src) loops in turfs never stop executing even if the turf they are linked to is deleted. The running proc is given the src of the new turf, causing the old proc to continue running under the new turf's instance.