Containers with families, trying to use less code

Get help using Construct 2

Post » Fri Feb 17, 2017 6:51 pm

Currently, Baddy is hard-coded in because if I try to use the badguy family instead, none of the enemies individually work by themselves, everything is triggered as one object and I can't put their detectors on the family, so none of the enemies have their own detctors. Will I have to just keep copying and pasting this code for every different enemy?Image
B
41
S
12
G
14
Posts: 1,122
Reputation: 11,268

Post » Fri Feb 17, 2017 7:48 pm

Families should do what you want. Can you make a smaller example, so we can see what you might be doing wrong?
ImageImageImage
B
71
S
22
G
249
Posts: 3,763
Reputation: 138,577

Post » Fri Feb 17, 2017 8:02 pm

Containers do not work with families. However, you can manually link objects together using a common variable value for instance (like linking the detectors with the sprite UID). You will need to explicitely pick objects though.
B
75
S
31
G
27
Posts: 1,000
Reputation: 20,735

Post » Fri Feb 17, 2017 8:08 pm

:oops: I completely missed the headline.
ImageImageImage
B
71
S
22
G
249
Posts: 3,763
Reputation: 138,577

Post » Fri Feb 17, 2017 9:48 pm

blackhornet wrote:Families should do what you want. Can you make a smaller example, so we can see what you might be doing wrong?

Sorry, I used a large example to cover all the possibilities.
Magistross wrote:Containers do not work with families. However, you can manually link objects together using a common variable value for instance (like linking the detectors with the sprite UID). You will need to explicitely pick objects though.

Yeah, I read that was the case. So, should I give each badguy a variable, put the detectors in each badguy's container, assign a variable to all the detectors and badguys, and pick each of them and give them the nearest UID?

Or should I just duplicate code? :?
B
41
S
12
G
14
Posts: 1,122
Reputation: 11,268

Post » Fri Feb 17, 2017 9:57 pm

@blackhornet @Magistross There's also this containerhelper behavior that allows for picking family children by UID, but I'm too stupid to understand how it could be useful: download/file.php?id=10540
B
41
S
12
G
14
Posts: 1,122
Reputation: 11,268

Post » Sat Feb 18, 2017 2:29 pm

Is there some other way of being able to reference families whilst maintaining individual instance profiling? I'd have thought duplicate event groups would have been really really discouraged, but how else can I use the events I'm using?
B
41
S
12
G
14
Posts: 1,122
Reputation: 11,268

Post » Sat Feb 18, 2017 2:48 pm

Zebbi wrote:Yeah, I read that was the case. So, should I give each badguy a variable, put the detectors in each badguy's container, assign a variable to all the detectors and badguys, and pick each of them and give them the nearest UID?

Or should I just duplicate code? :?


Do something like below.

On family "badguy" created
For each "badguy"
create/spawn detector
set variable "detector.parent" to "badguy.UID"

Then if the detector colides with whatever it is to collide with do:

On detector collides with whatever

for each detector
pick badguy by uid [detector.parent]
do events for badguy

Should work IIRC. Let me know if it does not, I will be using a similar method to link inventories to NPCs and Loot Containers in my current project.

Also family.uid=object.uid, you can also use that to check if a family member is a particular object type IIRC.
B
15
S
6
Posts: 85
Reputation: 1,195

Post » Sat Feb 18, 2017 7:30 pm

Pulstar wrote:
Zebbi wrote:Yeah, I read that was the case. So, should I give each badguy a variable, put the detectors in each badguy's container, assign a variable to all the detectors and badguys, and pick each of them and give them the nearest UID?

Or should I just duplicate code? :?


Do something like below.

On family "badguy" created
For each "badguy"
create/spawn detector
set variable "detector.parent" to "badguy.UID"

Then if the detector colides with whatever it is to collide with do:

On detector collides with whatever

for each detector
pick badguy by uid [detector.parent]
do events for badguy

Should work IIRC. Let me know if it does not, I will be using a similar method to link inventories to NPCs and Loot Containers in my current project.

Also family.uid=object.uid, you can also use that to check if a family member is a particular object type IIRC.

Gonna try this, should I still use containers at all, or just remove the two detectors from the container and spawn them? Also, is that definitely spawn and not create (two different processes)?

Also, how about turning each character left or right? Is that just a case of using foreach?
B
41
S
12
G
14
Posts: 1,122
Reputation: 11,268

Post » Sun Feb 19, 2017 8:23 am

In your situation I figure spawn might be more convenient.

I would remove the containers, otherwise you will end up with creating too many detectors and badguys. Bah, I am not sure if this would not create a feedback loop if you forget to remove the containers. Badguy spawns detector via event, detector spawns rest of container on event creating new badguy, badguy spawns new detector via event etc.
B
15
S
6
Posts: 85
Reputation: 1,195

Next

Return to How do I....?

Who is online

Users browsing this forum: Uglypenguin, Yahoo [Bot] and 11 guests