How do I Pick Family Instances Consistently Within Events?

Get help using Construct 2

Post » Sat Jun 06, 2015 8:34 pm

I'm working on a fighting game, and rather than duplicate the code for Fighter1/Fist1/HealthBar1 to have 2 (or more) fighters, I'm trying to leverage families, with objects being picked based on them having the same PlayerNumber instance variable.

I have this mostly working, but there are 2 particular situations where I'm running into a lot of issues.

Image
Here is where I'm trying to put the Fists and HealthBars at the right spot for each fighter, as well as resize the HealthBar appropriately. The stuff referencing Fist1/Fist2/Fighter1/Fighter2/Health1/Health2 is what I currently have working.

The stuff below just referencing Families does not work correctly (both Fists and HealthBars are stuck on Fighter1, while Fighter2 has nothing). It looks like the issue is that the Event is not correctly picking a Fighter instance, and so the Action just refers to the first Fighter it finds.

Image
Here is where I'm detecting active attacks, and calling Damage appropriately. The top stuff referencing Fist1/Fist2/Fighter1/Fighter2 is what I currently have working.

The stuff below just referencing Families does not work correctly (whenever either Fighter attacks, the other takes damage regardless of proximity to the former's fist). I think this is a similar problem to what I explained above, where the action is not using the same fighter that's referenced in the event (basically, Fist1 is always overlapping Fighter1, and then a different Fighter is found with a PlayerNumber separate from the Fist, and so that Fighter gets Damaged).

I have workarounds, and there are other things I could do differently, so I'm not trying to solve the problem so much as understand what's causing it. It's frustrating because Construct 2 is normally so automagical with Instance Picking, but that functionality seems to completely fall apart when dealing with families.

Any clue what I'm missing here?

Thanks!
B
3
Posts: 2
Reputation: 179

Post » Sun Jun 07, 2015 10:49 am

When creating events it's always necessary to reference the object you want the actions to refer to..

your first event would work if you picked the right fist for the right fighter..
Right now no fighters are referenced in the event..

So you probably mean for the first event:

system for each fighter
system pick fist by comparison fist.playernumber = fighter.playernumber
> fist set position to fighter
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Mon Jun 08, 2015 3:21 am

Ah, I was thinking that using the Fighter in the Fist's "Compare Instance Variable" value slot would end up picking that same fighter, but I see now that's not the case. Using "Pick By Comparison" instead works perfectly. Thanks!
B
3
Posts: 2
Reputation: 179


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 23 guests