T
Thurnok
Guest
Did a few search algorithms for this, but nothing came up that was what I was looking for, so...
Just wondering if there is a way to "programmatically" get the list of Child Objects a Parent Object contains? I know you can see the list in the Object editor, but I'd like to be able to get a list (in code) of the children for a parent. To explain why, what I wish to do is the following:
Create a parent object to contain the majority of functionality for all the child objects I create under it. Then create several child objects which may or may not have unique functionality, but have different sprites. Within a game room, add child objects where I specifically want "that" particular type of the object, but in addition, place the parent object in locations where I want to then have one of its children selected randomly at creation time to replace it ( instance_change() for example ).
I don't want to "statically" create a list of the child objects, because then in the future, if I add more child objects, I have to change the code to include those newly added child objects in the list. Rather, I would like to have the randomized code not have to change, by being able to grab the list of child objects to then randomly select from. This means I could add more child objects down the road and not have to update the code itself.
For example...
Create event for Parent object:
- check if this is the parent object as opposed to a child ( maybe: par = object_get_parent(object_index); )
- then, if par = -100 it is the parent object, not one of the children, so...
- get the list of children this parent has
- then select random(count children) + 1
- grab that numbered item from the list of children
- instance_change(the child item, true) // run destroy for parent, create for child
- if it is a child instead of the parent, possibly do other things here in the create event...
So being able to programmatically get the list of child objects then allows me to down the road add 30 more child objects without having to change the above code at all. Is there a way to do this currently (I didn't see one)? If not, anyone have a suggestion for a workaround to perform something similar (again without having to change code every time I add new child objects)?
Just wondering if there is a way to "programmatically" get the list of Child Objects a Parent Object contains? I know you can see the list in the Object editor, but I'd like to be able to get a list (in code) of the children for a parent. To explain why, what I wish to do is the following:
Create a parent object to contain the majority of functionality for all the child objects I create under it. Then create several child objects which may or may not have unique functionality, but have different sprites. Within a game room, add child objects where I specifically want "that" particular type of the object, but in addition, place the parent object in locations where I want to then have one of its children selected randomly at creation time to replace it ( instance_change() for example ).
I don't want to "statically" create a list of the child objects, because then in the future, if I add more child objects, I have to change the code to include those newly added child objects in the list. Rather, I would like to have the randomized code not have to change, by being able to grab the list of child objects to then randomly select from. This means I could add more child objects down the road and not have to update the code itself.
For example...
Create event for Parent object:
- check if this is the parent object as opposed to a child ( maybe: par = object_get_parent(object_index); )
- then, if par = -100 it is the parent object, not one of the children, so...
- get the list of children this parent has
- then select random(count children) + 1
- grab that numbered item from the list of children
- instance_change(the child item, true) // run destroy for parent, create for child
- if it is a child instead of the parent, possibly do other things here in the create event...
So being able to programmatically get the list of child objects then allows me to down the road add 30 more child objects without having to change the above code at all. Is there a way to do this currently (I didn't see one)? If not, anyone have a suggestion for a workaround to perform something similar (again without having to change code every time I add new child objects)?