ID:345660
 
I want to add multiple objects to a list and when I create a new object, that one is automaticly added to the list. Is there a possible way to do this. I know it would be something like:

mob/var/list/BattleChips = typesof(/obj/Battle_Chips/Regular).
I think I made a feature request for a newlist/typesof hybrid a long time ago, but that never stuck. (I tried doing "newlist(arglist(typesof()))")
proc/newtypes(types[])
. = list()
for(var/type in types)
. += new type

// Make a list of new battle chips
// but don't include the parent path
// because that doesn't have anything to it
mob var/BattleChips[] = newtypes(
typesof(
/obj/Battle_Chips/Regular
) - /obj/Battle_Chips/Regular)
// typesof() returns a list of paths, as you know
// The "- /blah" line is just to remove the parent
// from it.
You could make modifications on New.
mob
var/list/BattleChips = /obj/Battle_Chips/Regular

New()
if( ispath(BattleChips) )
var/types = typesof(BattleChips)
types -= BattleChips
BattleChips = new
for(var/_type in types)
BattleChips += new _type
return ..()
In response to Kaiochao
Kaiochao wrote:
I think I made a feature request for a newlist/typesof hybrid a long time ago, but that never stuck. (I tried doing "newlist(arglist(typesof()))")
> proc/newtypes(types[])
> . = list()
> for(var/type in types)
> . += new type
>
> // Make a list of new battle chips
> // but don't include the parent path
> // because that doesn't have anything to it
> mob var/BattleChips[] = newtypes(
> typesof(
> /obj/Battle_Chips/Regular
> ) - /obj/Battle_Chips/Regular)
> // typesof() returns a list of paths, as you know
> // The "- /blah" line is just to remove the parent
> // from it.
>


Tried it, and it came up with this error:
Test.dm:8:error: =: expected a constant expression
You'll probably just have to put it in mob/New(), then.