Refering to individual instances of family members in code?

0 favourites
  • 6 posts
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • First forum post, woo!!

    Alright so a friend and I are in development of a one-screen arcade style platformer, which has many of the same kind of enemy walking around the level. So, naturally, we used families to make sure all the different types of NPCs would interact with the player and the world the same way.

    We have one enemy type under the family as of now, and with one of them on screen, the code seemed to work nicely.

    (The enemy tries to avoid the player, and will climb up if above the player and climb down when below the player.)

    However, when multiple instances of this enemy were placed around the level, some of the enemies would float in the air for a little while when climbing up a ladder...

    It seems that the code for the enemy getting off the ladder isn't triggered since there are other enemies still on different ladders. How can we get the code to affect individual instances of the family members, rather than taking account to every member of the family?

  • have you tried (For Each) enemies, you will find it on >>System >> For Each>>> then choose the enemies

  • Here's my code...where's the best place to put that?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Gokee

    Normally you would place the (For Each Enemy) right before all the Events that affect the enemies so it will apply those events to the enemies but individually.

    Is hard to see who is who in the pictures as the family names are hiding in the picture but I guess most of those events are for the enemies so I will put it right at the top and just move all the events that you have in a sub event of the (for each)

  • I would be wary of using the "Else" condition when selecting groups of objects - instead use the inverse condition. Typically Else should be reserved for System conditions; you can get away with it when you're dealing with a single unique object but it becomes problematic when you have multiples instances of the same object. e.g.:

    If enemies.value = 1 do A

    Else do B

    In this situation if any one enemy has a value of 1 then A will be triggered for that picked group of enemies but B will not triggered at all, so any enemies with a value of not 1 will not react. The only time B is triggered is if NO enemies have a value of 1

    If enemies.value = 1 do A

    If enemies.value !=1 do B

    In this situation A will be triggered for enemies with a value of 1 and B will be triggered for enemies with any other value.

  • Thanks guys! I implemented both your suggestions and it now works like a charm!

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