Refering to individual instances of family members in code?

Get help using Construct 2

Post » Fri Jul 21, 2017 3:20 am

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. :D

Image

(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... :shock:

Image

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?
B
4
Posts: 3
Reputation: 206

Post » Fri Jul 21, 2017 3:25 am

have you tried (For Each) enemies, you will find it on >>System >> For Each>>> then choose the enemies
B
41
S
25
G
87
Posts: 309
Reputation: 48,096

Post » Fri Jul 21, 2017 3:41 am

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

Image

Image
B
4
Posts: 3
Reputation: 206

Post » Fri Jul 21, 2017 4:03 am

@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)
B
41
S
25
G
87
Posts: 309
Reputation: 48,096

Post » Fri Jul 21, 2017 10:14 am

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.
B
22
S
9
G
4
Posts: 476
Reputation: 4,327

Post » Sat Jul 22, 2017 8:18 pm

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

Image
B
4
Posts: 3
Reputation: 206


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 5 guests