How do I get an instance variable from a family child?

Get help using Construct 2

Post » Thu Feb 04, 2016 11:06 pm

Hi All,
I have a small predicament where I have two different npcs that exist in a family. Now each of these npcs has their own instance variable which is an ID. This ID doesn't actually ever change, as it points to a piece of content for that particular entity (a conversation for instance).

But when I add them to a family, I can't actually access that static instance variable any more. I can get hold of it by converting it to a JSON string, but I figured there might be an easier way.

This is different from the family instance variable, it's kind of one layer in instead. Another example might be that you have a fixed name on that particular entity, but again you wouldn't be able to access it via a family of npc types.

Is there another way to get around this that anyone might know of? Hope this question makes sense, I can add more clarity if needs be.

Thanks very much!
B
5
Posts: 22
Reputation: 278

Post » Thu Feb 04, 2016 11:12 pm

please provide snippet of code or .capx thanks JC
B
29
S
13
G
10
Posts: 355
Reputation: 8,312

Post » Fri Feb 05, 2016 9:59 am

Hello sir,
I've uploaded an uber simple case example for your / anyone else to look at:
https://www.dropbox.com/s/qfz7d81cmwtxn ... .capx?dl=0

You'll notice when clicking the boxes, the correct UID is shown so we know it's picking up the different instances, but there's no way to access the individual static ID on said instance. If however you look at the browser console log, you'll notice in the JSON output that the static ID value is actually visible (you'll notice a '1a' and a '2a').

Those are basically what I need to access.
B
5
Posts: 22
Reputation: 278

Post » Fri Feb 05, 2016 11:21 am

Is there a particular reason why do you not use a family instance variable?
B
23
S
3
G
1
Posts: 412
Reputation: 2,062

Post » Fri Feb 05, 2016 12:35 pm

Yes, if I use a family instance variable, that doesn't allow for a fixed unique property. So, for instance I could use a 'health' property on each different enemy, as that doesn't need any specific identity.

But if it's say a 'name' of an npc, then that needs to be set on the actual child itself, as you'd have different characters with different names assigned to them.

Something like that : P
B
5
Posts: 22
Reputation: 278

Post » Fri Feb 05, 2016 1:40 pm

Maybe I don't understand you correct, but isn't that what you want?
https://drive.google.com/file/d/0B5FlDY ... sp=sharing
B
23
S
3
G
1
Posts: 412
Reputation: 2,062

Post » Fri Feb 05, 2016 3:02 pm

Oh... Oh I see now...! I was doing it the wrong way round! *facepalm*

What I really need to do (which is what you've done Asmodean), is add the instance var to the family, then set it on the sprite that way instead, as it filters down to it (which I had no idea of).

It makes so much sense!

Thanks so much for that Asmodean, I owe you bigtime! :P
*bro hug*
B
5
Posts: 22
Reputation: 278


Return to How do I....?

Who is online

Users browsing this forum: Jazz813, mekonbekon, SnipG, Yozzik and 13 guests