How do I use families from javascript?

0 favourites
  • 5 posts
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • I've searched everywhere in the forum and documentation but can't find any mention on how to reference families in scripting. I'd like to know how to get the family name of an object I have a reference to, and how to reference a family for doing stuff.

    I SWEAR I RTFM

  • Families are referenced the same way as objects. For example:

    runtime.objects.Sprite.getFirstInstance();

    runtime.objects.FamilySprites.getFirstInstance();

    I'd like to know how to get the family name of an object I have a reference to

    It's usually the other way around - to get the object name of a family member use FamilyInstance.objectType.name

    I don't think it's possible to find which family this object belongs to. But you can try to pick family instance by object UID. Here is how I would do this with events:

    On Clicked Sprite
    EnemiesFamily pick by UID = Sprite.UID
    

    If the sprite is a member of EnemiesFamily, this event will pick it.

  • Thank you thank you dop2000!! You're always so helpful.

    However what I want is to translate an "On <family name> created" condition:

    I added an event listener for objects being created, and now have to check if they belong to that family.

    Or is there another way to translate that that you'd suggest?

    edit: also I just realized my approach doesn't even make sense because an object can be in many families. But still, how'd you go about that then?

  • Maybe I don't understand the issue, but can't you have the event listener for the family?

    runtime.objects.Enemies.addEventListener("instancecreate", (event) => {

    console.log("A new instance was created:", event.instance.objectType.name);

    });

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • WAIT YOU CAN DO THAT??? OMG I WAS LISTENING FOR EVERY OBJECT CREATION EVER AND THEN TRYING TO FILTER IT.

    thanks man lol .___. I'm dumb

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