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

0 favourites
  • 7 posts
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • 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!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • please provide snippet of code or .capx thanks JC

  • 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.

  • Is there a particular reason why do you not use a family instance variable?

  • 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

  • Maybe I don't understand you correct, but isn't that what you want?

    https://drive.google.com/file/d/0B5FlDY ... sp=sharing

  • 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!

    *bro hug*

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)