Calling functions with families

0 favourites
  • 5 posts
  • I'm trying to understand how I can call functions for each member of a family that meets certain conditions.

    In this example, I want all members of the enemies family to move away from the player if they have LOS. Enemies to the right of the player are moved using a 'simulate' action. Enemies to the left of the player are moved using a 'simulate' action inside function.

    When I move player to the right, all instances of enemies that have LOS move to the right. Bet when I move to the left, only once instance moves.

    It seems that functions only apply to one family member at a time. How can I make it so that all enemies to my left move using my function?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The fix is to add 'for each enemies' at the top condition, things get a bit weird with multiple instances.

  • Thanks, that worked!

    My game has several functions, with some functions being called from others. So when using families, is the rule to ALWAYS use a for/each condition when calling a function that performs actions on the family members? Does this apply when calling functions from functions? Or should I try to minimize functions use entirely? I'm using functions to keep my eventsheet clean, but maybe I shouldn't?

  • For each instance is good for any of the objects where you are checking them every tick like that. Function within function can get messy but they can be used if you need, however second function does not automatically see picked instances from the first function so you have to do something like pass through the UID of the instance in function 1 as a parameter to function 2.

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