Example:
for(var/Type in typesof(/obj))
Then grab each obj (and subtype) in the world, in a list.
ID:158475
![]() Aug 18 2009, 3:47 pm
|
|
![]() Aug 18 2009, 3:58 pm
|
|
So... what's the question exactly? And you can do that by:
|
Not objs...
As stated.. a 'dynamic type', meaning I have no way of knowing what it will be. That was simply an example... If you look at my example, you will understand what I am asking. : for(var/Type in typesof()) This goes through every type (/obj, /obj/Stuff, /obj/Tree, /obj/Whatever) under obj. Then basically what I want to do is for(var/[Type]/X in world) However that isn't acceptable. See the problem? EDIT: On a side note: Yes, I could loop through every atom in the world, then use if(istype()) to see if it matches said type... But when you're doing this for 50+ different types, and looping through every atom in the world each time, it becomes very wasteful of resources. |
As a general method:
proc/grab_of_type(type) Note even the above won't work for the non-datum types such as /client, /savefile. But there are only ever a handful of them, so you could account for them specially, and out of them you'll only ever really want to loop through /client - you're of course very unlikely to need to loop through all /lists or all /savefiles. You should try and limit how broad the loop is - if the dynamic object type can only logically be of a certain parent type, then you better loop through that instead, to make the loop shorter and more efficient. For example, maybe you're doing this in an item stacking system where an item is added to a container and you want to loop through that container's contents and find objects of a dynamic type, the one of the added item. In such a case then you conceivably only need to catch item objects, so you could just loop through for(var/obj/item/I in Container) instead of all datums. In other cases you may need to loop through all objs or atoms. |
Unfortunately not. It may well be possible for them to implement this, perhaps with a syntax like for(var/X as TYPE [in Container]), TYPE being a variable. Feature-request material?
|
Kaioken wrote:
Unfortunately not. It may well be possible for them to implement this, perhaps with a syntax like for(var/X as TYPE [in Container]), TYPE being a variable. Feature-request material? You can already do as 'mob|obj|turf', I don't see why it couldn't be allowed to include subtypes. Good suggestion. |