ID:141604
 
I have a for() loop that should loop through multiple types of areas and the turfs in them, but for some reason it only loops through one of the subtypes.

area/Type1/Type2
area/Type1/Type3
area/Type1/Type4
area/Type1/Type5

for(var/turf/T in locate(/area/Type1))
world<<"[T.x],[T.y]"

If I put 2 of each area on the map this SHOULD output 10 different turfs (if you include Type1 itself). However it only ever outputs 2, a pair from one specific subtype, usually the lowest on the list(5 first, if no 5 then 4, etc)

I figure I'm just doing something stupid in regards to area looping but I decided to ask for help.
The locate(/area/Type1) bit will find only the first /area/Type1 on the map. In order to do this, you'll have to use nested for loops.
What you want is typesof().
AJX wrote:
I figure I'm just doing something stupid in regards to area looping but I decided to ask for help.

Theres really no such thing as 'area looping'. To figure out whats wrong you need to understand how DM interprets this. See if you can't figure out whats wrong yourself =)

* locate() will return a reference, meaning one single /area object.

* In a for() loop, 'in [reference_here]' is the same as going through the references contents list if it is an atom.

What you need is the procedure 'typesof()', that returns a list of types that are children of the argument. Note that typesof() also returns the typepath itself that you feed it. i.e. typesof(/mob) will return a list with /mob in it and all subtypes of /mob.

I suggest the same method as Popisfizzy; it should be better than looping through typesof() and then looking for a single instance of each area type in it.
Damn. Lots of helpful responses vurry quick. Thanks all.

What I did is something like this:
var/A
var/L[]=typesof(/area/Type1)
for(A in L)
for(var/turf/T in locate(A))

It works perfectly, but is this a good way to go about it?

Thanks again all of you for your help.