[SOLVED]How do I set events properly using families

Just started using Construct 2? Post your questions here

Post » Wed Nov 11, 2015 4:21 am

To clarify the title of the thread:

I have a family called 'Enemies' which contains all of the sprites for monsters in the game. Each monster sprite has an instance variable called 'Onhit' that when changed to '1' causes an animation to happen among a few other things such as spawning a damage number sprite.

I want to slim my code down (I made code for a bullet colliding with every single monster sprite which lead to a lot of events) and make it so when a bullet overlaps anything from the 'Enemies' family it changes the instance variable of the specific monster that was hit ('Onhit' to '1').

If I do something like:

'Bullet on collision with (family)Enemies'

Any action that occurs as a result of that will affect every monster sprite that is within the 'Enemies' family.

Thank you.
Last edited by varr on Fri Nov 13, 2015 5:40 am, edited 1 time in total.
B
10
S
2
G
2
Posts: 87
Reputation: 1,274

Post » Wed Nov 11, 2015 8:37 pm

In your above example any action taken will only affect the one member of the family hit with the on collision.

Look at changing the instance variable to the family rather than the individual sprites.
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
33
G
47
Posts: 1,194
Reputation: 30,812

Post » Wed Nov 11, 2015 9:08 pm

I apologize. I should have paid more attention to what I was writing.

I have now created a family instance variable called 'FamilyOnhit' and changed it so that every monster has an event that triggers on 'FamilyOnhit' = 1 rather than using their own individual instance variable called 'Onhit'.

When a bullet collides with the Enemies family it sets FamilyOnhit to 1 and affects every monster not just the one that was hit. How would I change the code to have it only trigger an event for the specific monster that was hit? How would I subtract from the 'hp' instance variable of a sprite called 'mushroom' (which is part of the Enemies family) using the an event regarding the bullet colliding with the Enemies family?

If I code:

Bullet on collision with (family)Enemies: Subtract 1 from mushroom.hp

It will trigger that event when the bullet collides with any sprite that belongs to the Enemies family.
B
10
S
2
G
2
Posts: 87
Reputation: 1,274

Post » Wed Nov 11, 2015 10:19 pm

please post a link to the capx so we an have a look , or a screen grab of the events ?
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
33
G
47
Posts: 1,194
Reputation: 30,812

Post » Thu Nov 12, 2015 3:30 am

I have the following example for when a specific monster is hit:

Image

Image

I have separate events like those pictured above for each monster sprite in the game. Is there any way to do the above using Families in order to lessen the amount of code?
B
10
S
2
G
2
Posts: 87
Reputation: 1,274

Post » Thu Nov 12, 2015 10:22 am

I'm going to make some assumptions so I apologise if I get this wrong.

I don't think you quite grasped the power of families (that sounds a bit like a line out of a Disney film :-))

Let's say you have several monsters which we will call mushroom crab, toadstool cat, fungus dog and mouldy fish. All of these monsters are added to a family which we will call family monsters.

From your example above we could have

If sword beam is overlapping family monsters
AND
family monster instant variable active equals 1
AND
sword beams instant variable critical is greater than 25

THEN

set family monsters instance variable on hit to one

So this would make no difference if a crab, cat, dog or fish are overlapped by the sword beam.

----------------------

And in your 2nd section basically everywhere where you are saying moon crab change that to family monsters.

Here is a simple example of family use

https://goo.gl/Ri97RD
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
33
G
47
Posts: 1,194
Reputation: 30,812

Post » Fri Nov 13, 2015 3:37 am

You're right with your assumptions (I am a noob). I have been using Construct 2 on and off for a year and I have just discovered the use of Families. I also just finished changing all of the code over for the enemies to make use of the Family and it all works smoothly, Thanks!
B
10
S
2
G
2
Posts: 87
Reputation: 1,274


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 1 guest