getting a family from an instance, what is the best way in this case?

0 favourites
  • 2 posts
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • Hey all,

    There are a number of ways in scripting to end up with an instance, without knowing much about it,

    Such as runtime.objects.SomeFamily.getFirstInstance().children();

    In this case, I am looking for all children that belong to a specific family.

    for (const character in runtime.objects.characters.instances()) {
    	
    	//how to easily get this:
    	const effects = character.children //where children belong to family "effects
    	//obviously that wont work, but I also dont see a way to to check...
    	//...if an instance belongs to a family.
    	//I can see a property "ObjectType" for checking instance types, but not family
    
    	//this is what I am doing instead:
    	for(const effect in character.children()) {
    		if (effect.instVars.aVariableExistingOnFamilyEffects !== undefined) {
    			//this specific variable exists only on the family "effects"
    			//since this child inst has that variable...
    			//...we can treat it as the family now.
    		}
    	}
    }
    
    

    Checking for a variable on the object that belongs to the family I want seems like a hacky way to go about going from a parent to checking for children of a specific family type.

    I can't see that this is an uncommon operation, is there a better way of going about it?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Seems like a proper way to handle this is missing, maybe having a getFamilies() API on the objectClass interface would make sense.

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