Object as a child of another?

Discussion and feedback on Construct 2

Post » Tue Jun 09, 2015 6:27 pm

I don't think this is currently possible, if it is I'd love to know how, but if not I'd like to suggest it.

Currently I can only assign text, a boolean or an integer to an object. Could it be an option that we can assign other objects to an object in a similar way?

I think it would be easier to say have an array attached to a sprite which could hold inventory data or something like that, than to have a global array. Sure the global array method works if you've only got one player, but using such a method in conjunction with say the multiplayer object can start to make the array a bit more confusing, especially for beginners. If the array could be set as a child of the sprite and each sprite had their own array, referenced like a behaviour can be would make construct easier to work with in my opinion.

Another use could be to have a sprite as a child of another sprite which could function like a container, where if the parent is destroyed all children are subsequently destroyed, but if a child is destroyed its parents and sisters are not destroyed. Again, I think this extra aspect could make construct a lot more intuitive than it currently is.

~ Briggs
Nothing goes unanswered!
B
24
S
5
G
1
Posts: 434
Reputation: 3,446

Post » Tue Jun 09, 2015 6:31 pm

You could have the uid of the object inside said variable maybe?
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
52
S
22
G
18
Posts: 2,122
Reputation: 17,093

Post » Tue Jun 09, 2015 6:34 pm

Aphrodite wrote:You could have the uid of the object inside said variable maybe?


But then if I wanted multiple objects? I would need multiple variables or use a cdl of the uids in a string variable; which would then need to be iterated over every time I wanted to use a child object. I know it works that way, it's just not as tidy than I feel it could be.
Nothing goes unanswered!
B
24
S
5
G
1
Posts: 434
Reputation: 3,446

Post » Tue Jun 09, 2015 6:37 pm

You can already pair an array with an object by using containers. You can do more elaborate stuff by using uid's. For example your second example could be done like so:

on body created
--- create head
--- set body.head to head.uid
--- create arm
--- set body.arm to arm.uid

on body destroyed
--- pick head by uid body.head
------ destroy head
--- pick arm by uid body.arm
------ destroy arm


And you just use the pick by uid condition whenever you want to reference the child objects.

Edit:
In another way if you want a parent to have any number of children then you give the children a parent uid in the child instead.
B
91
S
31
G
102
Posts: 5,232
Reputation: 67,250

Post » Tue Jun 09, 2015 7:19 pm

R0J0hound wrote:[...]

Edit:
In another way if you want a parent to have any number of children then you give the children a parent uid in the child instead.


But say the parent was destroyed, wouldn't you have to loop all objects that could be children to check that the destroyed object was their parent.

I can see that it's possible with the tool-set provided, but I still think it could really help workflow. Coming from working with OOPLs I feel like this would aid the developer.
Nothing goes unanswered!
B
24
S
5
G
1
Posts: 434
Reputation: 3,446

Post » Tue Jun 09, 2015 8:01 pm

I too wish that C2 took a more OOP approach, but it's not likely to happen due to C2's architecture. Perhaps C3 will, but I doubt it considering Construct's target audience, and the fact that C2 projects will work in C3.

Fortunately in this scenario, the workaround in C2 isn't onerous. If you add all objects to a family, add a "Parent UID" instance variable, and use it to populate each object's parent, you can destroy all children with just 2 events:

Image
B
62
S
19
G
8
Posts: 341
Reputation: 12,075


Return to Construct 2 General

Who is online

Users browsing this forum: brushfe and 6 guests