How do I get the plugin id from an instance of an object?

0 favourites
  • 5 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • I have a function that takes as input an instance of any object. Based on the plugin of the instance itself (Sprite, SVG, 9Patch, Text...) i want to perform certain different actions. Given an instance, how can i get its plugin back (using scripting, not normal events)?

    Here's an example of what I want to do:

    const spriteInstance = runtime.objects.player.getFirstPickedInstance();
    const svgInstance = runtime.objects.circle.getFirstPickedInstance();
    const textInstance = runtime.objects.title.getFirstPickedInstance();
    
    function performAction(instance) {
    	if(getPlugin(instance) == "Sprite") console.log("This is a sprite");
    	if(getPlugin(instance) == "SVG") console.log("This is a SVG object");
    	if(getPlugin(instance) == "Text") console.log("This is a text object");
    }
    
    performAction(spriteInstance);
    performAction(svgInstance);
    performAction(textInstance);
    
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • If you want to do something like identify if an instance is a Sprite instance, you can use inst instanceof ISpriteInstance. The instance class names are documented in the manual, e.g. here for Sprite.

  • Thank you Ashley! That works! However, I'm unable to find the instance class for 9Patch objects. I think they don't have one (?). Is there any way I can tell if an instance is a 9Patch?

  • There isn't a specialized script interface for 9-patch at the moment - so unfortunately there doesn't seem to be a good way to identify those kinds of instances... maybe we need to add a new script API to cover that.

  • Thank you Ashley! That works! However, I'm unable to find the instance class for 9Patch objects. I think they don't have one (?). Is there any way I can tell if an instance is a 9Patch?

    Sorry, I'm from another thread of the post you helped me today-check the messages there again-there is a problem

    construct.net/en/forum/construct-3/how-do-i-8/change-text-html-element-184802

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