How do I Pick Multiple Families

0 favourites
  • 5 posts
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • 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:

    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?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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?.

  • 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.

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)