How do I Pick Multiple Families

Get help using Construct 2

Post » Wed Nov 26, 2014 2:18 pm

Got this idea, I want to create an Enemy Family that control movement and a lot of other families to control the way of attack of my enemies. For now I just created the EnemyMelee Family. Now, I want this:

If EnemyMelee is near the Player (Im using Line of Sight Behaviour on family EnemyMelee) and Enemy isnt Death (a variable called enemyState on family Enemy) attack it. This seems to work well

But my problem is when the EnemyMelee is not near the player and Enemy is not death. It doesnt seems to work using the old trick pick familyA, pick familyB by familyB.UID = familyA.UID for picking multiple families. With the code as it is now, It just work for the enemy with the lower UID, It doesnt work with others enemies.

Im using this code:
Image

Here's an example of the behaviour: http://www.xhelos.com/c2/example/index.html

Here's the capx: http://www.xhelos.com/c2/example/solofile.capx

I really need to make this work on differents families. My idea is that is to create differents kinds of family to control their AI. For example create a enemyShooter Family and a enemyBoss family, so I just put the enemies in their respectives families and they win a new behaviour. That's why I cant put all the code in one family.

Using the Pick instance with UID doesnt work also.

What can be wrong with this code?
B
10
S
2
G
1
Posts: 48
Reputation: 1,265

Post » Wed Nov 26, 2014 2:36 pm

You need to use For each. If there is only a single object type, this format works (it implicitly does the For each for you). Because you are operating on two families at once, you need to do the extra work of cycling though each object explicitly.
In the top two examples, do a For each famEnemyMelee after the Line-of-sight.
In the functions, break those apart. Have a subevent that picks the object and does its actions, then have a second subevent (at teh same level) to do the second objects actions.
ImageImageImage
B
71
S
22
G
241
Posts: 3,734
Reputation: 134,494

Post » Wed Nov 26, 2014 2:49 pm

Well, seems to work :), even without breaking the function. I will test it on the real project to see if it is working. You make me wonder, Why do you recommend to break the functions in subevents?.
Last edited by jeeba on Wed Nov 26, 2014 3:03 pm, edited 1 time in total.
B
10
S
2
G
1
Posts: 48
Reputation: 1,265

Post » Wed Nov 26, 2014 3:02 pm

I expected it wouldn't work, but if it does, then fine. This is the confusing thing though, it can be hard to know exactly when you need to do the work yourself, and when C2 can figure it out itself. I'm guessing since the two picks aren't referencing the other one (like in the first case) then it's OK.
ImageImageImage
B
71
S
22
G
241
Posts: 3,734
Reputation: 134,494

Post » Wed Nov 26, 2014 3:56 pm

The functions work because only one UID is ever in the context, referencing the same object through multiple families.

The "For each" is needed because the system condition "Pick by evaluate" won't implicitely loop through all famEnemyMelee UIDs. As a rule of thumb, when you are using expressions and can't use "Self" to reference your object, take for granted that you'll need a for each.
B
71
S
30
G
25
Posts: 984
Reputation: 19,503


Return to How do I....?

Who is online

Users browsing this forum: dop2000, Yahoo [Bot] and 41 guests