How do I get the child's instance variable inside families

Get help using Construct 2

Post » Tue Mar 04, 2014 7:59 am

Example:
Player hit objects in families.
I want to decrease the health of that object.

How Can I do?
B
3
Posts: 2
Reputation: 179

Post » Tue Mar 04, 2014 8:15 am

Construct2's typecasting :D
Code: Select all
+ Player: on collide with familyObject
+ SpecificObject: UID = familyObject.UID
         -> SpecificObject: substract 1 from hp
B
66
S
22
G
14
Posts: 1,484
Reputation: 16,511

Post » Tue Mar 04, 2014 1:44 pm

@Yann Typecasting ? Thanks for this one, I was still calling a custom function with familyObject.UID, and then selecting the specificObject by its UID in the function.

PS : As I didn't understand right away, I made it as an example in attachment.
Blue and Black are in the family "movable", Red is not.
Blue has a "speed" variable, and black has "hp". On collision, depending on the object colliding, the corresponding action will be called.
You do not have the required permissions to view the files attached to this post.
B
17
S
8
G
4
Posts: 473
Reputation: 6,191

Post » Tue Mar 04, 2014 3:24 pm

@Guizmus yes, typecasting
B
66
S
22
G
14
Posts: 1,484
Reputation: 16,511

Post » Tue Mar 04, 2014 4:56 pm

Um you shouldn't need to pick via uid, families do all that for you.
All you have to do is subtract from the family, as the particular object is already picked.
Just make sure the variable belongs to that family.
You do not have the required permissions to view the files attached to this post.
Image ImageImage
B
169
S
50
G
173
Posts: 8,317
Reputation: 110,278

Post » Wed Mar 05, 2014 6:50 am

@newt you do need to pick via UID if you want to know what is the particular object type of the family member you picked (yes it's usefull sometimes)

However, I agree with you on the fact that if he wants to decrease the hp of any object in the family, the hp should be a family variable, not an instance variable.
B
66
S
22
G
14
Posts: 1,484
Reputation: 16,511

Post » Wed Mar 05, 2014 5:19 pm

Actually I would probably go with an instance variable there since picking by uid is limited to a specific instance.
That is unless you really have to pick outside of that event, like a function.
Image ImageImage
B
169
S
50
G
173
Posts: 8,317
Reputation: 110,278

Post » Wed Mar 05, 2014 6:40 pm

@newt using an instance variable would be redundant in this case.
B
66
S
22
G
14
Posts: 1,484
Reputation: 16,511

Post » Sun May 15, 2016 5:31 pm

newt wrote:Um you shouldn't need to pick via uid, families do all that for you.
All you have to do is subtract from the family, as the particular object is already picked.
Just make sure the variable belongs to that family.


OK. I know this is over 2 years later, my apologies. But how did you get a Family Instance Variable with the same name as a Object Instance Variable??
B
6
S
2
Posts: 34
Reputation: 512

Post » Sun May 15, 2016 5:53 pm

You don't.
If you use the object in the condition, then you use the object's instance variable.
If you use the family in the condition, then you use the family variable.
If you want to pass a value to an entire family, or all instances in the same event, you have to go outside picking.
A function works well for that.
Image ImageImage
B
169
S
50
G
173
Posts: 8,317
Reputation: 110,278

Next

Return to How do I....?

Who is online

Users browsing this forum: batto, bclikesyou, Lancifer and 30 guests