How do I get the plugin id from a behavior?

  • I'm writing a behavior that needs to adjust its behavior for different plugins. So I need to be able to check which plugin the behavior is attached to. But type.plugin doesn't seem to have any properties that could be used to identify it. I suspect I'm missing something obvious, but I've been all through the docs and can't find anything.

    Does anyone know how to get the plugin id or otherwise identify it?

    Thanks.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • TrickyWidget

    You might check official drag&drop behavior.

  • You might check official drag&drop behavior.

    Thanks for the tip. I went all through that code a few times, but I can't see what it is you're indicating.

    I did find a purely JavaScript way to do it:

    if (typeof cr.plugins_.Spritefont2 == "function")
    	if (cr.plugins_.Spritefont2.prototype.isPrototypeOf(this.inst.type.plugin))[/code:11xuxh4b]
    That works well enough, but it's kind of clunky.  I'm hoping there's a C2-specific approach that's more direct.  Something like [i]this.inst.type.plugin.id[/i] would be a gem.
  • 	function GetDragDropBehavior(inst)
    	{
    		var i, len;
    		for (i = 0, len = inst.behavior_insts.length; i < len; i++)
    		{
    			if (inst.behavior_insts[i] instanceof behaviorProto.Instance)
    				return inst.behavior_insts[i];
    		}
    		
    		return null;
    	};
    [/code:3hk231xp]
    
    , the core is [code:3hk231xp]inst.behavior_insts[i] instanceof behaviorProto.Instance[/code:3hk231xp]
    -> object instanceof type
    Sorry for not clearly.
  • To test if there has Cr.plugins.spritefont2, just

    Cr.plugins.sprutefont2 != null

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