ID:156118
 
Is there a way I can make a type be treated like a list (kind of like you can a mob) for instance:
 for(var/i in usr)
world<<"I'm in the user's contents"


Kind of like how usr automatically refers to CONTENTS.

And also would it be possible to do something like:
 src += i


or... is this just not possible because the mob case is because of DM's syntax?
It'd be better just to type out "src.contents+=i" so you can quickly skim and understand the code. A tad bit more typing now, less headaches later, 'better safe than sorry', insert any other quote of the like. As for the whole type treated like a list, they aren't treated like a list. It's redirected to usr.contents as a special syntax.

All atoms have contents, and atom is the ancestor of all mapable objects. So, As long as the type you want is mapable, you can always say
 for(var/i in x.contents)
//...

and be assured that as long as 'x' is mapable, it will have the possibility of contents. Does this help you?
In response to Jacksanto
It's not an atom.
You can give the datum a list variable (call it contents if you wish) and query datum.contents. It's a little extra typing but it's what you have to do.

Something like
Container
var/list/contents = list()


and then you'd just have to use
for(var/i in instanceOfContainer.contents)
world<<"I'm in the instance's contents
In response to Jamckell
If it's not an atom, then it would of been useful for you to of said in the main post.
That aside, datums can just as easily have lists attatched to them as atoms can.

//Defining and adding the list 'Contents'
MyDatum
var/list/Contents = list()

//Adding something to the Datum's 'Contents'
var/obj/MyObj/O = new()
var/MyDatum/Instance = locate() in world
Instance.Contents += O

//Giving a small output per element in Datum's 'Contents'
var/MyDatum/Instance = locate()in world
for(var/i in Instance.MyDatum)
world<<"Why hello there"