On collision with a family member subtract a variable

Get help using Construct 3!

Post » Wed Oct 25, 2017 10:24 pm

Hi there, thanks for taking a look ... this is more of a 'wonder if i could'

So I have a family called 'Enemies' and within that grouping there are 10 Objects, all Sprites and all of them have their own numeric instance variable called Damage.

What I would like to happen is that if the player collides with a member of the Enemies family, it picks the object it has collided with and subtracts that object's Damage variable from a Global Variable.

Apologies if this doesn't make sense ...
B
13
S
3
Posts: 63
Reputation: 903

Post » Wed Oct 25, 2017 10:52 pm

could be wrong, but I think you can simply do an on collision with family substract damage from global variable in this case
B
11
S
2
Posts: 26
Reputation: 695

Post » Wed Oct 25, 2017 10:53 pm

Yes you can do that, did you try it as described?
B
48
S
19
G
87
Posts: 2,316
Reputation: 51,516

Post » Wed Oct 25, 2017 10:59 pm

Thank you for responding @plinkie and @InsaneSnake

Yes, and this is what happens for me ...

Image
B
13
S
3
Posts: 63
Reputation: 903

Post » Wed Oct 25, 2017 11:14 pm

Assuming you have set up instance variables for each individual object called Damage, this is why Families are powerful because you have a 'Family Instance variable'. That is what you're referencing there but you haven't used it. Create a family instance variable called Damage then every enemy will have it (you don't need to add the variable individually to each member of Enemies). You can only reference Enemies.Damage if it's setup for family, otherwise you need to reference individual enemies, EnemyA.Damage, EnemyB.Damage. Better to group in a family, which is what you're trying to do I can see but didn't quite get there yet :D
B
48
S
19
G
87
Posts: 2,316
Reputation: 51,516

Post » Wed Oct 25, 2017 11:20 pm

@plinkie

Thank you so much! Brilliantly explained!
B
13
S
3
Posts: 63
Reputation: 903

Post » Wed Oct 25, 2017 11:28 pm

No problem, good luck and feel free to post back here if you have any problem with using families.
B
48
S
19
G
87
Posts: 2,316
Reputation: 51,516


Return to How do I...?

Who is online

Users browsing this forum: No registered users and 1 guest