ID:1066985
 
Keywords: child, list, types
Applies to:DM Language
Status: Open

Issue hasn't been assigned a status value.
I think there should be a built-in var that lists the types of the object definitions directly contained by the specific parent object. This should be a top-level var, working as high as datum.

This is basically a list of all the direct children objects of a given parent object. Here is an example of a soft coded proc which accomplishes the same basic thing, although it shouldn't output the list items with the full paths, since we already know what the parent is.

The issue here is that a soft coded proc just wouldn't be as efficient as a hard coded var. We already have a top-level parent_type var, so it should make logical sense to have this as a counterpart. We even have a vars list var, to list all the vars belonging to an object, so this shouldn't be that big of a jump to make. I mean, this is object oriented programming, and we don't even have a built-in means of listing child objects! Sure, we have a contents list var, but that's not top-level and only works on mappable objects.

If we assume that this var can be changed, then it would also be more intuitive to use than the newlist() proc, since you could just add to the pre-existing list.

You could also make good use of this list var if you wanted to specifically give child objects certain properties, but not the parent. I would use this to parse through all the existing objects, then combine it with the vars list var to get a hierarchy tree of all the vars, which I could then setup to edit at runtime, for testing/debugging purposes.

Let us know if you would like this to be implemented, and why.
+1
So what's the programmatic use-case here? I understand the feature in itself (quite similar to RTTI in C++ or Reflection for Java), but I am struggling a bit to see what it enables/makes easier in a DM games dev scenario.
Had to repost this from memory after I got error 500! So annoying!

It's kind of hard to think of an example, since this isn't something that would be used very often.

Let's say we have several different colored mobs:
mob
red
wizard
slime
green
giant
dragon
blue
shark
serpent


We want to switch these mobs to a different parent color (with different properties), whenever something triggers that to happen. To do this easily, we could use the child_types list var.

mob
proc
switch_colors
var
list/S = list(".mob/red.child_types", ".mob/green.child_types", ".mob/blue.child_types")
S.Swap(1,2)
S.Swap(2,3)
S.Swap(3,1)


I'm not very experienced with lists, and this is just an example, so don't expect it to work perfectly. I don't even know if you can actually use Swap() on a built-in list var like this, although it's being used indirectly (on a list of child_types lists).

I imagine you could also use the child_types list for something like in-game shops or marketplaces, that need objects to be sorted in certain ways.

A child_types list var could make it a lot easier to create new objects during runtime.