ID:148961
 
I've had many troubles with the block() proc as of recently, so I'm here to confirm that I am using it correctly.

Let me throw this snippet of code at you, that's giving me troubles:

        for(var/a = 1, a < world.maxz+1, a++)
if(a != z_level)
for(var/area/Start_Zone/C in block(locate(1,1,a),locate(world.maxx,world.maxy,a)))
del(C)

This little tidbit of code is supposed to go through all of the Z levels of a .dmp (once loaded) and delete all of the areas on each of the Z levels (save the level equivlant to the 'z_level' var). Now...this code seems to do absolutely nothing, so I'm wondering if I'm using block() correctly.

I am seeking help on either another method of doing this, or how I can properly use the block() proc for this.

Thanks.
block() only returns the turfs within the given range, not areas or other atoms. When you try to filter the areas out of a list of turfs, you get nothing.

You could try filtering all areas in world:
    for(var/area/A in world)


or you could create a list of areas and loop through it for greater efficiency.
var/list/AreaList = list()

area
New()
..()
AreaList += src
Del()
AreaList -= src
..()

// and use this within your proc
for(var/area/A in AreaList)


In response to Shadowdarke (#1)
Ah, I see now. I thought that block() could be used just like range(), but in a simular manner.

What I need to do is only locate the areas on a certain Z level of the map, not the whole world.

But I can't figure out how to go about doing that. My knowledge is a bit limited in the field of areas.
In response to Malver (#2)
I think that the z value for an area is the first z level it appears on, with may not suit your needs. If your areas do not span z levels you could just compare the z of each area to your target z.

You could loop through all the turfs on that z layer and add their loc (a turf's loc is always an area) to the list of areas on that z layer. With large maps this will be slow though.
In response to Shadowdarke (#3)
Shadowdarke wrote:
I think that the z value for an area is the first z level it appears on, with may not suit your needs. If your areas do not span z levels you could just compare the z of each area to your target z.

Is there a way to prevent areas from spanning over Z levels?

You could loop through all the turfs on that z layer and add their loc (a turf's loc is always an area) to the list of areas on that z layer. With large maps this will be slow though.

This is definitely not an option, it's too inefficient for my likings. ;)